diff options
author | jsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4> | 2005-04-20 01:10:00 +0000 |
---|---|---|
committer | jsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4> | 2005-04-20 01:10:00 +0000 |
commit | 0766e8763c0c87e7190f60f6e754b76614ccc326 (patch) | |
tree | 14947a42d28eff84a4539188551c43e15026cc3f /gcc | |
parent | caac37c241c47fe1c95a28c8824bf863cc947260 (diff) | |
download | gcc-0766e8763c0c87e7190f60f6e754b76614ccc326.tar.gz |
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.
testsuite:
* 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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@98429 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/c-typeck.c | 6 | ||||
-rw-r--r-- | gcc/c.opt | 8 | ||||
-rw-r--r-- | gcc/doc/invoke.texi | 14 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/Wint-to-pointer-cast-1.c | 12 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/Wint-to-pointer-cast-2.c | 12 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/Wint-to-pointer-cast-3.c | 20 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/Wpointer-to-int-cast-1.c | 12 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/Wpointer-to-int-cast-2.c | 12 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/Wpointer-to-int-cast-3.c | 21 |
11 files changed, 128 insertions, 3 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 42cea0a76a9..6b1c0404a13 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +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. diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c index 9c82bbe6019..a39d703c0f7 100644 --- a/gcc/c-typeck.c +++ b/gcc/c-typeck.c @@ -3259,7 +3259,8 @@ build_c_cast (tree type, tree expr) && 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)) @@ -3271,7 +3272,8 @@ build_c_cast (tree type, tree expr) 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. */ diff --git a/gcc/c.opt b/gcc/c.opt index 2f643b31980..ee456fc45cc 100644 --- a/gcc/c.opt +++ b/gcc/c.opt @@ -226,6 +226,10 @@ Wimport 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 @@ -314,6 +318,10 @@ Wpointer-arith 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 diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index cb6f175eb47..cb1e7761289 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -221,13 +221,15 @@ Objective-C and Objective-C++ Dialects}. -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 @@ -3179,6 +3181,16 @@ warning about it. 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 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index bf8cccd520f..8b2e027ca41 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +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 diff --git a/gcc/testsuite/gcc.dg/Wint-to-pointer-cast-1.c b/gcc/testsuite/gcc.dg/Wint-to-pointer-cast-1.c new file mode 100644 index 00000000000..ddb10577d08 --- /dev/null +++ b/gcc/testsuite/gcc.dg/Wint-to-pointer-cast-1.c @@ -0,0 +1,12 @@ +/* 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" } */ +} diff --git a/gcc/testsuite/gcc.dg/Wint-to-pointer-cast-2.c b/gcc/testsuite/gcc.dg/Wint-to-pointer-cast-2.c new file mode 100644 index 00000000000..e4c980dd42c --- /dev/null +++ b/gcc/testsuite/gcc.dg/Wint-to-pointer-cast-2.c @@ -0,0 +1,12 @@ +/* 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" } */ +} diff --git a/gcc/testsuite/gcc.dg/Wint-to-pointer-cast-3.c b/gcc/testsuite/gcc.dg/Wint-to-pointer-cast-3.c new file mode 100644 index 00000000000..457a53afedd --- /dev/null +++ b/gcc/testsuite/gcc.dg/Wint-to-pointer-cast-3.c @@ -0,0 +1,20 @@ +/* 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" } */ +} diff --git a/gcc/testsuite/gcc.dg/Wpointer-to-int-cast-1.c b/gcc/testsuite/gcc.dg/Wpointer-to-int-cast-1.c new file mode 100644 index 00000000000..d9362a2d119 --- /dev/null +++ b/gcc/testsuite/gcc.dg/Wpointer-to-int-cast-1.c @@ -0,0 +1,12 @@ +/* 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" } */ +} diff --git a/gcc/testsuite/gcc.dg/Wpointer-to-int-cast-2.c b/gcc/testsuite/gcc.dg/Wpointer-to-int-cast-2.c new file mode 100644 index 00000000000..a8d97ea6d2a --- /dev/null +++ b/gcc/testsuite/gcc.dg/Wpointer-to-int-cast-2.c @@ -0,0 +1,12 @@ +/* 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" } */ +} diff --git a/gcc/testsuite/gcc.dg/Wpointer-to-int-cast-3.c b/gcc/testsuite/gcc.dg/Wpointer-to-int-cast-3.c new file mode 100644 index 00000000000..12bfd4284d4 --- /dev/null +++ b/gcc/testsuite/gcc.dg/Wpointer-to-int-cast-3.c @@ -0,0 +1,21 @@ +/* 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" } */ +} |