+2005-04-20 Michael Pogue <michael.pogue@sun.com>
+ Joseph S. Myers <joseph@codesourcery.com>
+
+ * c.opt (Wint-to-pointer-cast, Wpointer-to-int-cast): New options.
+ * c-typeck.c (build_c_cast): Check these options.
+ * doc/invoke.texi: Document these options.
+
2005-04-20 Kazu Hirata <kazu@cs.umass.edu>
* tree-ssa-phiopt.c: Update a comment about the pass.
&& TYPE_ALIGN (TREE_TYPE (type)) > TYPE_ALIGN (TREE_TYPE (otype)))
warning ("cast increases required alignment of target type");
- if (TREE_CODE (type) == INTEGER_TYPE
+ if (warn_pointer_to_int_cast
+ && TREE_CODE (type) == INTEGER_TYPE
&& TREE_CODE (otype) == POINTER_TYPE
&& TYPE_PRECISION (type) != TYPE_PRECISION (otype)
&& !TREE_CONSTANT (value))
warning ("cast from function call of type %qT to non-matching "
"type %qT", otype, type);
- if (TREE_CODE (type) == POINTER_TYPE
+ if (warn_int_to_pointer_cast
+ && TREE_CODE (type) == POINTER_TYPE
&& TREE_CODE (otype) == INTEGER_TYPE
&& TYPE_PRECISION (type) != TYPE_PRECISION (otype)
/* Don't warn about converting any constant. */
C ObjC C++ ObjC++
Deprecated. This switch has no effect.
+Wint-to-pointer-cast
+C ObjC Var(warn_int_to_pointer_cast) Init(1)
+Warn when there is a cast to a pointer from an integer of a different size
+
Winvalid-offsetof
C++ ObjC++ Var(warn_invalid_offsetof) Init(1)
Warn about invalid uses of the \"offsetof\" macro
C ObjC C++ ObjC++ Var(warn_pointer_arith)
Warn about function pointer arithmetic
+Wpointer-to-int-cast
+C ObjC Var(warn_pointer_to_int_cast) Init(1)
+Warn when a pointer is cast to an integer of a different size
+
Wprotocol
ObjC ObjC++ Var(warn_protocol) Init(1)
Warn if inherited methods are unimplemented
-Wformat-security -Wformat-y2k @gol
-Wimplicit -Wimplicit-function-declaration -Wimplicit-int @gol
-Wimport -Wno-import -Winit-self -Winline @gol
+-Wno-int-to-pointer-cast @gol
-Wno-invalid-offsetof -Winvalid-pch @gol
-Wlarger-than-@var{len} -Wlong-long @gol
-Wmain -Wmissing-braces -Wmissing-field-initializers @gol
-Wmissing-format-attribute -Wmissing-include-dirs @gol
-Wmissing-noreturn @gol
-Wno-multichar -Wnonnull -Wpacked -Wpadded @gol
--Wparentheses -Wpointer-arith -Wredundant-decls @gol
+-Wparentheses -Wpointer-arith -Wno-pointer-to-int-cast @gol
+-Wredundant-decls @gol
-Wreturn-type -Wsequence-point -Wshadow @gol
-Wsign-compare -Wstrict-aliasing -Wstrict-aliasing=2 @gol
-Wswitch -Wswitch-default -Wswitch-enum @gol
The restrictions on @samp{offsetof} may be relaxed in a future version
of the C++ standard.
+@item -Wno-int-to-pointer-cast @r{(C only)}
+@opindex Wno-int-to-pointer-cast
+Suppress warnings from casts to pointer type of an integer of a
+different size.
+
+@item -Wno-pointer-to-int-cast @r{(C only)}
+@opindex Wno-pointer-to-int-cast
+Suppress warnings from casts from a pointer to an integer type of a
+different size.
+
@item -Winvalid-pch
@opindex Winvalid-pch
Warn if a precompiled header (@pxref{Precompiled Headers}) is found in
+2005-04-20 Joseph S. Myers <joseph@codesourcery.com>
+
+ * gcc.dg/Wint-to-pointer-cast-1.c,
+ gcc.dg/Wint-to-pointer-cast-2.c, gcc.dg/Wint-to-pointer-cast-3.c,
+ gcc.dg/Wpointer-to-int-cast-1.c, gcc.dg/Wpointer-to-int-cast-2.c,
+ gcc.dg/Wpointer-to-int-cast-3.c: New tests.
+
2005-04-18 Francois-Xavier Coudert <coudert@clipper.ens.fr>
PR fortran/16861
--- /dev/null
+/* Test -Wint-to-pointer-cast - on by default. */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+char c;
+
+void *
+f (void)
+{
+ return (void *) c; /* { dg-warning "warning: cast to pointer from integer of different size" } */
+}
--- /dev/null
+/* Test -Wint-to-pointer-cast. */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "-Wint-to-pointer-cast" } */
+
+char c;
+
+void *
+f (void)
+{
+ return (void *) c; /* { dg-warning "warning: cast to pointer from integer of different size" } */
+}
--- /dev/null
+/* Test -Wno-int-to-pointer-cast. */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "-Wno-int-to-pointer-cast" } */
+
+char c;
+
+void *
+f (void)
+{
+ return (void *) c;
+}
+
+void *p;
+
+char
+g (void)
+{
+ return (char) p; /* { dg-warning "warning: cast from pointer to integer of different size" } */
+}
--- /dev/null
+/* Test -Wpointer-to-int-cast - on by default. */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+void *p;
+
+char
+f (void)
+{
+ return (char) p; /* { dg-warning "warning: cast from pointer to integer of different size" } */
+}
--- /dev/null
+/* Test -Wpointer-to-int-cast. */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "-Wpointer-to-int-cast" } */
+
+void *p;
+
+char
+f (void)
+{
+ return (char) p; /* { dg-warning "warning: cast from pointer to integer of different size" } */
+}
--- /dev/null
+/* Test -Wno-pointer-to-int-cast. */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "-Wno-pointer-to-int-cast" } */
+
+void *p;
+
+char
+f (void)
+{
+ return (char) p;
+}
+
+
+char c;
+
+void *
+g (void)
+{
+ return (void *) c; /* { dg-warning "warning: cast to pointer from integer of different size" } */
+}