Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 5 Jan 2003 18:02:42 -0800 (PST)
From:      Peter Wemm <peter@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 23238 for review
Message-ID:  <200301060202.h0622gx3097951@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=23238

Change 23238 by peter@peter_itanic2 on 2003/01/05 18:02:34

	Add some warning/error knobs for catching the evilness of assigning
	integers to pointers, either implicitly or through stupidity.  I've
	turned this on in /etc/make.conf on my test boxes.  It isn't pretty.
	CFLAGS=    -O -pipe -Werror-bad-pointer-cast
	COPTFLAGS= -O -pipe -Werror-bad-pointer-cast
	
	The first test here is probably harmless.  There is no need to get upset
	about trying to store a pointer in an integer, eg: for hashing bits.

Affected files ...

.. //depot/projects/ia64/contrib/gcc/c-decl.c#9 edit
.. //depot/projects/ia64/contrib/gcc/c-tree.h#6 edit
.. //depot/projects/ia64/contrib/gcc/c-typeck.c#6 edit

Differences ...

==== //depot/projects/ia64/contrib/gcc/c-decl.c#9 (text+ko) ====

@@ -349,6 +349,11 @@
 
 int mesg_implicit_function_declaration = -1;
 
+/* Nonzero means message about casts with integer/pointer size mismatches;
+ 1 means warning; 2 means error.  */
+
+int mesg_bad_pointer_cast = 1;
+
 /* Nonzero means give string constants the type `const char *'
    to get extra warnings from them.  These warnings will be too numerous
    to be useful, except in thoroughly ANSIfied programs.  */
@@ -658,6 +663,12 @@
     mesg_implicit_function_declaration = 1;
   else if (!strcmp (p, "-Wno-implicit-function-declaration"))
     mesg_implicit_function_declaration = 0;
+  else if (!strcmp (p, "-Werror-bad-pointer-cast"))
+    mesg_bad_pointer_cast = 2;
+  else if (!strcmp (p, "-Wbad-pointer-cast"))
+    mesg_bad_pointer_cast = 1;
+  else if (!strcmp (p, "-Wno-bad-pointer-cast"))
+    mesg_bad_pointer_cast = 0;
   else if (!strcmp (p, "-Wimplicit-int"))
     warn_implicit_int = 1;
   else if (!strcmp (p, "-Wno-implicit-int"))

==== //depot/projects/ia64/contrib/gcc/c-tree.h#6 (text+ko) ====

@@ -371,6 +371,9 @@
 /* Warn about implicit declarations.  1 = warning, 2 = error.  */
 extern int mesg_implicit_function_declaration;
 
+/* Warn about bad pointer casts.  1 = warning, 2 = error.  */
+extern int mesg_bad_pointer_cast;
+
 /* In c-decl.c */
 extern void finish_incomplete_decl PARAMS ((tree));
 

==== //depot/projects/ia64/contrib/gcc/c-typeck.c#6 (text+ko) ====

@@ -3767,7 +3767,16 @@
 	  && TREE_CODE (otype) == POINTER_TYPE
 	  && TYPE_PRECISION (type) != TYPE_PRECISION (otype)
 	  && !TREE_CONSTANT (value))
+#if 1	/* mostly harmless */
 	warning ("cast from pointer to integer of different size");
+#else
+	{
+	  if (mesg_bad_pointer_cast == 2)
+	    error ("cast from pointer to integer of different size");
+	  else if (mesg_bad_pointer_cast == 1)
+	    warning ("cast from pointer to integer of different size");
+	}
+#endif
 
       if (warn_bad_function_cast
 	  && TREE_CODE (value) == CALL_EXPR
@@ -3779,7 +3788,12 @@
 	  && TYPE_PRECISION (type) != TYPE_PRECISION (otype)
 	  /* Don't warn about converting any constant.  */
 	  && !TREE_CONSTANT (value))
-	warning ("cast to pointer from integer of different size");
+	{
+	  if (mesg_bad_pointer_cast == 2)
+	    error ("cast to pointer from integer of different size");
+	  else if (mesg_bad_pointer_cast == 1)
+	    warning ("cast to pointer from integer of different size");
+	}
 
       ovalue = value;
       value = convert (type, value);
@@ -4243,8 +4257,11 @@
 	     && TREE_CODE (TREE_OPERAND (rhs, 0)) == INTEGER_CST
 	     && integer_zerop (TREE_OPERAND (rhs, 0))))
 	{
-	  warn_for_assignment ("%s makes pointer from integer without a cast",
-			       errtype, funname, parmnum);
+	  if (mesg_bad_pointer_cast == 2)
+	    error ("%s makes pointer from integer without a cast", errtype);
+	  else
+	    warn_for_assignment ("%s makes pointer from integer without a cast",
+				 errtype, funname, parmnum);
 	  return convert (type, rhs);
 	}
       return null_pointer_node;

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe p4-projects" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200301060202.h0622gx3097951>