This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Patch to add -Wno-int-to-pointer-cast and -Wno-pointer-to-int-cast


This patch adds options to control the C front end warnings (on by
default) for casts between pointers and integers of different size.

There are two patches here.  The first will be applied to
csl-sol210-3_4-branch after testing on i386-pc-solaris2.10.  The
second has been bootstrapped with no regressions on
x86_64-unknown-linux-gnu; applied to mainline.

-- 
Joseph S. Myers               http://www.srcf.ucam.org/~jsm28/gcc/
    jsm@polyomino.org.uk (personal mail)
    joseph@codesourcery.com (CodeSourcery mail)
    jsm28@gcc.gnu.org (Bugzilla assignments and CCs)

2005-04-20  Michael Pogue  <michael.pogue@sun.com>
            Joseph S. Myers  <joseph@codesourcery.com>

	* gcc/c.opt (Wint-to-pointer-cast, Wpointer-to-int-cast): New
	options.
	* gcc/c-common.c (warn_pointer_to_int_cast,
	warn_int_to_pointer_cast): New variables.
	* gcc/c-common.h (warn_pointer_to_int_cast,
	warn_int_to_pointer_cast): New declarations.
	* gcc/c-opts.c (c_common_handle_option): Handle these options.
	* gcc/c-typeck.c (build_c_cast): Check these options.
	* gcc/doc/invoke.texi: Document these options.
	* gcc/testsuite/gcc.dg/Wint-to-pointer-cast-1.c,
	gcc/testsuite/gcc.dg/Wint-to-pointer-cast-2.c,
	gcc/testsuite/gcc.dg/Wint-to-pointer-cast-3.c,
	gcc/testsuite/gcc.dg/Wpointer-to-int-cast-1.c,
	gcc/testsuite/gcc.dg/Wpointer-to-int-cast-2.c,
	gcc/testsuite/gcc.dg/Wpointer-to-int-cast-3.c: New tests.

Index: gcc/c-common.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/c-common.c,v
retrieving revision 1.476.4.8
diff -u -r1.476.4.8 c-common.c
--- gcc/c-common.c	23 Aug 2004 18:02:39 -0000	1.476.4.8
+++ gcc/c-common.c	19 Oct 2004 22:12:55 -0000
@@ -396,6 +396,14 @@
 
 int warn_bad_function_cast;
 
+/* Warn when casting a pointer to an integer whose size is different. */
+
+int warn_pointer_to_int_cast = 1;
+
+/* Warn when casting to a pointer from an integer of different size. */
+
+int warn_int_to_pointer_cast = 1;
+
 /* Warn about traditional constructs whose meanings changed in ANSI C.  */
 
 int warn_traditional;
Index: gcc/c-common.h
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/c-common.h,v
retrieving revision 1.216.2.4.6.1
diff -u -r1.216.2.4.6.1 c-common.h
--- gcc/c-common.h	23 Sep 2004 07:27:04 -0000	1.216.2.4.6.1
+++ gcc/c-common.h	19 Oct 2004 22:12:55 -0000
@@ -561,6 +561,14 @@
 
 extern int warn_bad_function_cast;
 
+/* Warn when casting a pointer to an integer whose size is different. */
+
+extern int warn_pointer_to_int_cast;
+
+/* Warn when casting to a pointer from an integer of different size. */
+
+extern int warn_int_to_pointer_cast;
+
 /* Warn about traditional constructs whose meanings changed in ANSI C.  */
 
 extern int warn_traditional;
Index: gcc/c-opts.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/c-opts.c,v
retrieving revision 1.96.4.7
diff -u -r1.96.4.7 c-opts.c
--- gcc/c-opts.c	18 Feb 2004 00:09:03 -0000	1.96.4.7
+++ gcc/c-opts.c	19 Oct 2004 22:12:56 -0000
@@ -496,6 +496,10 @@
       /* Silently ignore for now.  */
       break;
 
+    case OPT_Wint_to_pointer_cast:
+      warn_int_to_pointer_cast = value;
+      break;
+
     case OPT_Winvalid_offsetof:
       warn_invalid_offsetof = value;
       break;
@@ -575,6 +579,10 @@
       warn_pointer_arith = value;
       break;
 
+    case OPT_Wpointer_to_int_cast:
+      warn_pointer_to_int_cast = value;
+      break;
+
     case OPT_Wprotocol:
       warn_protocol = value;
       break;
Index: gcc/c-typeck.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/c-typeck.c,v
retrieving revision 1.272.2.9
diff -u -r1.272.2.9 c-typeck.c
--- gcc/c-typeck.c	8 Jun 2004 17:14:56 -0000	1.272.2.9
+++ gcc/c-typeck.c	19 Oct 2004 22:12:56 -0000
@@ -3124,7 +3124,8 @@
 	  && 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))
@@ -3135,7 +3136,8 @@
 	  && TREE_CODE (type) != TREE_CODE (otype))
 	warning ("cast does not match function 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.  */
Index: gcc/c.opt
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/c.opt,v
retrieving revision 1.17.12.2
diff -u -r1.17.12.2 c.opt
--- gcc/c.opt	18 Feb 2004 00:09:03 -0000	1.17.12.2
+++ gcc/c.opt	19 Oct 2004 22:12:56 -0000
@@ -257,6 +257,10 @@
 C ObjC C++ ObjC++
 Deprecated.  This switch has no effect.
 
+Wint-to-pointer-cast
+C ObjC
+Warn when there is a cast to a pointer from an integer of a different size
+
 Winvalid-offsetof
 C++ ObjC++
 Warn about invalid uses of the \"offsetof\" macro
@@ -332,6 +336,10 @@
 C ObjC C++ ObjC++
 Warn about function pointer arithmetic
 
+Wpointer-to-int-cast
+C ObjC
+Warn when a pointer is cast to an integer of a different size
+
 Wprotocol
 ObjC ObjC++
 Warn if inherited methods are unimplemented

--- gcc/doc/invoke.texi.orig	2004-10-06 20:15:08.000000000 +0000
+++ gcc/doc/invoke.texi	2005-04-19 19:34:27.000000000 +0000
@@ -220,12 +220,14 @@
 -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 @gol
 -Wmissing-format-attribute  -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 @gol
 -Wswitch  -Wswitch-default  -Wswitch-enum @gol
@@ -2968,6 +2970,16 @@
 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 -rupN gcc/testsuite/gcc.dg/Wint-to-pointer-cast-1.c gcc/testsuite/gcc.dg/Wint-to-pointer-cast-1.c
--- gcc/testsuite/gcc.dg/Wint-to-pointer-cast-1.c	1970-01-01 00:00:00.000000000 +0000
+++ gcc/testsuite/gcc.dg/Wint-to-pointer-cast-1.c	2005-04-19 19:22:15.000000000 +0000
@@ -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 -rupN gcc/testsuite/gcc.dg/Wint-to-pointer-cast-2.c gcc/testsuite/gcc.dg/Wint-to-pointer-cast-2.c
--- gcc/testsuite/gcc.dg/Wint-to-pointer-cast-2.c	1970-01-01 00:00:00.000000000 +0000
+++ gcc/testsuite/gcc.dg/Wint-to-pointer-cast-2.c	2005-04-19 19:26:35.000000000 +0000
@@ -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 -rupN gcc/testsuite/gcc.dg/Wint-to-pointer-cast-3.c gcc/testsuite/gcc.dg/Wint-to-pointer-cast-3.c
--- gcc/testsuite/gcc.dg/Wint-to-pointer-cast-3.c	1970-01-01 00:00:00.000000000 +0000
+++ gcc/testsuite/gcc.dg/Wint-to-pointer-cast-3.c	2005-04-19 19:24:24.000000000 +0000
@@ -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 -rupN gcc/testsuite/gcc.dg/Wpointer-to-int-cast-1.c gcc/testsuite/gcc.dg/Wpointer-to-int-cast-1.c
--- gcc/testsuite/gcc.dg/Wpointer-to-int-cast-1.c	1970-01-01 00:00:00.000000000 +0000
+++ gcc/testsuite/gcc.dg/Wpointer-to-int-cast-1.c	2005-04-19 19:23:05.000000000 +0000
@@ -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 -rupN gcc/testsuite/gcc.dg/Wpointer-to-int-cast-2.c gcc/testsuite/gcc.dg/Wpointer-to-int-cast-2.c
--- gcc/testsuite/gcc.dg/Wpointer-to-int-cast-2.c	1970-01-01 00:00:00.000000000 +0000
+++ gcc/testsuite/gcc.dg/Wpointer-to-int-cast-2.c	2005-04-19 19:26:46.000000000 +0000
@@ -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 -rupN gcc/testsuite/gcc.dg/Wpointer-to-int-cast-3.c gcc/testsuite/gcc.dg/Wpointer-to-int-cast-3.c
--- gcc/testsuite/gcc.dg/Wpointer-to-int-cast-3.c	1970-01-01 00:00:00.000000000 +0000
+++ gcc/testsuite/gcc.dg/Wpointer-to-int-cast-3.c	2005-04-19 19:25:21.000000000 +0000
@@ -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" } */
+}

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:
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.

diff -rupN GCC.orig/gcc/c-typeck.c GCC/gcc/c-typeck.c
--- GCC.orig/gcc/c-typeck.c	2005-04-16 10:31:54.000000000 +0000
+++ GCC/gcc/c-typeck.c	2005-04-19 19:38:38.000000000 +0000
@@ -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 -rupN GCC.orig/gcc/c.opt GCC/gcc/c.opt
--- GCC.orig/gcc/c.opt	2005-04-07 08:11:38.000000000 +0000
+++ GCC/gcc/c.opt	2005-04-19 23:15:13.000000000 +0000
@@ -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 -rupN GCC.orig/gcc/doc/invoke.texi GCC/gcc/doc/invoke.texi
--- GCC.orig/gcc/doc/invoke.texi	2005-04-16 10:32:13.000000000 +0000
+++ GCC/gcc/doc/invoke.texi	2005-04-19 19:43:50.000000000 +0000
@@ -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 -rupN GCC.orig/gcc/testsuite/gcc.dg/Wint-to-pointer-cast-1.c GCC/gcc/testsuite/gcc.dg/Wint-to-pointer-cast-1.c
--- GCC.orig/gcc/testsuite/gcc.dg/Wint-to-pointer-cast-1.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/Wint-to-pointer-cast-1.c	2005-04-19 19:22:15.000000000 +0000
@@ -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 -rupN GCC.orig/gcc/testsuite/gcc.dg/Wint-to-pointer-cast-2.c GCC/gcc/testsuite/gcc.dg/Wint-to-pointer-cast-2.c
--- GCC.orig/gcc/testsuite/gcc.dg/Wint-to-pointer-cast-2.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/Wint-to-pointer-cast-2.c	2005-04-19 19:26:35.000000000 +0000
@@ -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 -rupN GCC.orig/gcc/testsuite/gcc.dg/Wint-to-pointer-cast-3.c GCC/gcc/testsuite/gcc.dg/Wint-to-pointer-cast-3.c
--- GCC.orig/gcc/testsuite/gcc.dg/Wint-to-pointer-cast-3.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/Wint-to-pointer-cast-3.c	2005-04-19 19:24:24.000000000 +0000
@@ -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 -rupN GCC.orig/gcc/testsuite/gcc.dg/Wpointer-to-int-cast-1.c GCC/gcc/testsuite/gcc.dg/Wpointer-to-int-cast-1.c
--- GCC.orig/gcc/testsuite/gcc.dg/Wpointer-to-int-cast-1.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/Wpointer-to-int-cast-1.c	2005-04-19 19:23:05.000000000 +0000
@@ -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 -rupN GCC.orig/gcc/testsuite/gcc.dg/Wpointer-to-int-cast-2.c GCC/gcc/testsuite/gcc.dg/Wpointer-to-int-cast-2.c
--- GCC.orig/gcc/testsuite/gcc.dg/Wpointer-to-int-cast-2.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/Wpointer-to-int-cast-2.c	2005-04-19 19:26:46.000000000 +0000
@@ -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 -rupN GCC.orig/gcc/testsuite/gcc.dg/Wpointer-to-int-cast-3.c GCC/gcc/testsuite/gcc.dg/Wpointer-to-int-cast-3.c
--- GCC.orig/gcc/testsuite/gcc.dg/Wpointer-to-int-cast-3.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/Wpointer-to-int-cast-3.c	2005-04-19 19:25:21.000000000 +0000
@@ -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" } */
+}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]