From owner-p4-projects Sun Jan 5 18: 2:47 2003 Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id EC5B637B405; Sun, 5 Jan 2003 18:02:43 -0800 (PST) Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 6B95A37B401 for ; Sun, 5 Jan 2003 18:02:43 -0800 (PST) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 13DCF43EC5 for ; Sun, 5 Jan 2003 18:02:43 -0800 (PST) (envelope-from peter@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.12.6/8.12.6) with ESMTP id h0622gfh097955 for ; Sun, 5 Jan 2003 18:02:42 -0800 (PST) (envelope-from peter@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.12.6/8.12.6/Submit) id h0622gx3097951 for perforce@freebsd.org; Sun, 5 Jan 2003 18:02:42 -0800 (PST) Date: Sun, 5 Jan 2003 18:02:42 -0800 (PST) Message-Id: <200301060202.h0622gx3097951@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to peter@freebsd.org using -f From: Peter Wemm Subject: PERFORCE change 23238 for review To: Perforce Change Reviews Sender: owner-p4-projects@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG 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