aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos O'Donell <carlos@codesourcery.com>2006-01-05 19:07:16 +0000
committerCarlos O'Donell <carlos@gcc.gnu.org>2006-01-05 19:07:16 +0000
commit8d1c7aef72e3770b6efe5270de519e68f906a0b7 (patch)
tree15cf481d09f0cb7055c11c72680efb49ec41df87
parent32ce4048fb9f801ace0b534b37d2ffc1a2be3068 (diff)
downloadgcc-8d1c7aef72e3770b6efe5270de519e68f906a0b7.zip
gcc-8d1c7aef72e3770b6efe5270de519e68f906a0b7.tar.gz
gcc-8d1c7aef72e3770b6efe5270de519e68f906a0b7.tar.bz2
c-typeck.c (build_c_cast): Always warn when casting from a pointer to an integer of different size...
gcc/ 2006-01-05 Carlos O'Donell <carlos@codesourcery.com> * c-typeck.c (build_c_cast): Always warn when casting from a pointer to an integer of different size, even if the node was constant. gcc/testsuite 2006-01-05 Carlos O'Donell <carlos@codesourcery.com> * gcc.dg/cast-1.c: Add new warning. * gcc.dg/cast-2.c: Likewise. * gcc.dg/cast-3.c: Likewise. * gcc.dg/format/cast-1.c: Likewise. * gcc.dg/cast-4.c: New testcase. From-SVN: r109386
-rw-r--r--gcc/ChangeLog6
-rw-r--r--gcc/c-typeck.c8
-rw-r--r--gcc/testsuite/ChangeLog8
-rw-r--r--gcc/testsuite/gcc.dg/cast-1.c2
-rw-r--r--gcc/testsuite/gcc.dg/cast-2.c2
-rw-r--r--gcc/testsuite/gcc.dg/cast-3.c2
-rw-r--r--gcc/testsuite/gcc.dg/cast-4.c13
-rw-r--r--gcc/testsuite/gcc.dg/format/cast-1.c2
8 files changed, 37 insertions, 6 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 026dade..6f86398 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+2006-01-05 Carlos O'Donell <carlos@codesourcery.com>
+
+ * c-typeck.c (build_c_cast): Always warn when casting
+ from a pointer to an integer of different size, even if
+ the node was constant.
+
2006-01-05 Richard Guenther <rguenther@suse.de>
PR tree-optimization/22555
diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c
index 81fc40b..176ba7e 100644
--- a/gcc/c-typeck.c
+++ b/gcc/c-typeck.c
@@ -3508,8 +3508,12 @@ build_c_cast (tree type, tree expr)
if (TREE_CODE (type) == INTEGER_TYPE
&& TREE_CODE (otype) == POINTER_TYPE
- && TYPE_PRECISION (type) != TYPE_PRECISION (otype)
- && !TREE_CONSTANT (value))
+ && TYPE_PRECISION (type) != TYPE_PRECISION (otype))
+ /* Unlike conversion of integers to pointers, where the
+ warning is disabled for converting constants because
+ of cases such as SIG_*, warn about converting constant
+ pointers to integers. In some cases it may cause unwanted
+ sign extension, and a warning is appropriate. */
warning (OPT_Wpointer_to_int_cast,
"cast from pointer to integer of different size");
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 640c926..eb11257 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,11 @@
+2006-01-05 Carlos O'Donell <carlos@codesourcery.com>
+
+ * gcc.dg/cast-1.c: Add new warning.
+ * gcc.dg/cast-2.c: Likewise.
+ * gcc.dg/cast-3.c: Likewise.
+ * gcc.dg/format/cast-1.c: Likewise.
+ * gcc.dg/cast-4.c: New testcase.
+
2006-01-05 Richard Guenther <rguenther@suse.de>
PR tree-optimization/22555
diff --git a/gcc/testsuite/gcc.dg/cast-1.c b/gcc/testsuite/gcc.dg/cast-1.c
index e3d79db..8924264 100644
--- a/gcc/testsuite/gcc.dg/cast-1.c
+++ b/gcc/testsuite/gcc.dg/cast-1.c
@@ -37,5 +37,5 @@ f (void)
(void *) c; /* { dg-warning "warning: cast to pointer from integer of different size" } */
(void *) (char) 1;
(char) p; /* { dg-warning "warning: cast from pointer to integer of different size" } */
- (char) (void *) 1;
+ (char) (void *) 1; /* { dg-warning "warning: cast from pointer to integer of different size" } */
}
diff --git a/gcc/testsuite/gcc.dg/cast-2.c b/gcc/testsuite/gcc.dg/cast-2.c
index 0f84c22..eff465e 100644
--- a/gcc/testsuite/gcc.dg/cast-2.c
+++ b/gcc/testsuite/gcc.dg/cast-2.c
@@ -37,5 +37,5 @@ f (void)
(void *) c; /* { dg-warning "warning: cast to pointer from integer of different size" } */
(void *) (char) 1;
(char) p; /* { dg-warning "warning: cast from pointer to integer of different size" } */
- (char) (void *) 1;
+ (char) (void *) 1; /* { dg-warning "warning: cast from pointer to integer of different size" } */
}
diff --git a/gcc/testsuite/gcc.dg/cast-3.c b/gcc/testsuite/gcc.dg/cast-3.c
index 656bf6d..26a38cb 100644
--- a/gcc/testsuite/gcc.dg/cast-3.c
+++ b/gcc/testsuite/gcc.dg/cast-3.c
@@ -37,5 +37,5 @@ f (void)
(void *) c; /* { dg-warning "warning: cast to pointer from integer of different size" } */
(void *) (char) 1;
(char) p; /* { dg-warning "warning: cast from pointer to integer of different size" } */
- (char) (void *) 1;
+ (char) (void *) 1; /* { dg-warning "warning: cast from pointer to integer of different size" } */
}
diff --git a/gcc/testsuite/gcc.dg/cast-4.c b/gcc/testsuite/gcc.dg/cast-4.c
new file mode 100644
index 0000000..32b02cb
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cast-4.c
@@ -0,0 +1,13 @@
+/* Test warnings when casting from a constant integer to pointer.
+ Test with -pedantic-errors. */
+/* Origin: Carlos O'Donell <carlos@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu99 -pedantic-errors" } */
+
+extern int i;
+char c;
+void
+f (void)
+{
+ c = (char)&i; /* { dg-warning "warning: cast from pointer to integer of different size" } */
+}
diff --git a/gcc/testsuite/gcc.dg/format/cast-1.c b/gcc/testsuite/gcc.dg/format/cast-1.c
index 78a4f52..76e7cc5 100644
--- a/gcc/testsuite/gcc.dg/format/cast-1.c
+++ b/gcc/testsuite/gcc.dg/format/cast-1.c
@@ -12,5 +12,5 @@ f (int x)
{
printf("%s", x); /* { dg-warning "format" } */
printf((char *)(size_t)"%s", x); /* { dg-warning "format" } */
- printf((char *)(char)"%s", x);
+ printf((char *)(char)"%s", x); /* { dg-warning "warning: cast from pointer to integer of different size" } */
}