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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@109386
138bc75d-0d04-0410-961f-
82ee72b054a4
+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
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");
+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
(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" } */
}
(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" } */
}
(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" } */
}
--- /dev/null
+/* 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" } */
+}
{
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" } */
}