Commit 53a2494e by Joseph Myers

c.opt (Wint-to-pointer-cast, [...]): New options.

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.

From-SVN: r98429
parent 7195b414
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.
......
......@@ -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. */
......
......@@ -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
......
......@@ -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
......
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
......
/* 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" } */
}
/* 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" } */
}
/* 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" } */
}
/* 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" } */
}
/* 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" } */
}
/* 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" } */
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment