[PATCH] Allow 64bit warnings on 32bit targets
Andi Kleen
ak@muc.de
Fri Dec 19 19:02:00 GMT 2003
gcc gives some warnings ("cast from pointer to integer of different
size" etc.) only with 64bit targets. This patch adds a new flag
-W64bit to enable them for 32bit targets too. This is useful to do a
quick check if the code is 64bit clean even when you are compiling for
32bit.
Patch for mainline. Bootstrapped and test suite run with no new regressions.
Please consider applying. I don't have a CVS account.
-Andi
2003-12-19 Andi Kleen <ak@muc.de>
* doc/invoke.texi (Warning Options): Document -W64bit
* c.opt: Add -W64bit
* c-opts.c (c_common_handle_option): Handle warn_64bit.
* c-common.c, c-common.h: (warn_64bit) Add new variable.
* c-typeck.c (build_c_cast) Check for it.
Index: gcc/c-common.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-common.c,v
retrieving revision 1.468
diff -u -u -r1.468 c-common.c
--- gcc/c-common.c 15 Dec 2003 06:28:13 -0000 1.468
+++ gcc/c-common.c 19 Dec 2003 14:25:13 -0000
@@ -451,6 +451,9 @@
int warn_old_style_definition;
+/* Warn for likely 64-bit unsafe constructs even when not 64-bit */
+
+int warn_64bit;
/* ObjC language option variables. */
Index: gcc/c-common.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-common.h,v
retrieving revision 1.211
diff -u -u -r1.211 c-common.h
--- gcc/c-common.h 15 Dec 2003 06:28:13 -0000 1.211
+++ gcc/c-common.h 19 Dec 2003 14:25:13 -0000
@@ -618,6 +619,9 @@
extern int warn_old_style_definition;
+/* Warn for likely 64-bit unsafe constructs even when not 64-bit */
+
+extern int warn_64bit;
/* ObjC language option variables. */
Index: gcc/c-opts.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-opts.c,v
retrieving revision 1.94
diff -u -u -r1.94 c-opts.c
--- gcc/c-opts.c 5 Nov 2003 21:09:03 -0000 1.94
+++ gcc/c-opts.c 19 Dec 2003 14:25:13 -0000
@@ -554,6 +554,10 @@
warn_old_style_definition = value;
break;
+ case OPT_W64bit:
+ warn_64bit = value;
+ break;
+
case OPT_Wold_style_cast:
warn_old_style_cast = value;
break;
Index: gcc/c-typeck.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-typeck.c,v
retrieving revision 1.265
diff -u -u -r1.265 c-typeck.c
--- gcc/c-typeck.c 13 Dec 2003 04:11:19 -0000 1.265
+++ gcc/c-typeck.c 19 Dec 2003 14:25:19 -0000
@@ -3049,9 +3049,10 @@
if (TREE_CODE (type) == INTEGER_TYPE
&& TREE_CODE (otype) == POINTER_TYPE
- && TYPE_PRECISION (type) != TYPE_PRECISION (otype)
+ && (TYPE_PRECISION (type) != TYPE_PRECISION (otype)
+ || (warn_64bit && TYPE_PRECISION (type) < 64))
&& !TREE_CONSTANT (value))
- warning ("cast from pointer to integer of different size");
+ warning ("cast from pointer to integer of possibly different size");
if (warn_bad_function_cast
&& TREE_CODE (value) == CALL_EXPR
@@ -3060,10 +3061,11 @@
if (TREE_CODE (type) == POINTER_TYPE
&& TREE_CODE (otype) == INTEGER_TYPE
- && TYPE_PRECISION (type) != TYPE_PRECISION (otype)
+ && (TYPE_PRECISION (type) != TYPE_PRECISION (otype)
+ || (warn_64bit && TYPE_PRECISION (type) < 64))
/* Don't warn about converting any constant. */
&& !TREE_CONSTANT (value))
- warning ("cast to pointer from integer of different size");
+ warning ("cast to pointer from integer of possibly different size");
if (TREE_CODE (type) == POINTER_TYPE
&& TREE_CODE (otype) == POINTER_TYPE
Index: gcc/c.opt
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c.opt,v
retrieving revision 1.17
diff -u -u -r1.17 c.opt
--- gcc/c.opt 25 Sep 2003 01:25:50 -0000 1.17
+++ gcc/c.opt 19 Dec 2003 14:25:19 -0000
@@ -172,6 +172,10 @@
C ObjC C++ ObjC++
Synonym for -Wcomment
+W64bit
+C C++
+Warn 64-bit specific warnings even for 32bit targets
+
Wconversion
C ObjC C++ ObjC++
Warn about possibly confusing type conversions
Index: gcc/doc/invoke.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/invoke.texi,v
retrieving revision 1.368
diff -u -u -r1.368 invoke.texi
--- gcc/doc/invoke.texi 11 Dec 2003 10:22:42 -0000 1.368
+++ gcc/doc/invoke.texi 19 Dec 2003 14:25:42 -0000
@@ -233,7 +233,7 @@
-Wsystem-headers -Wtrigraphs -Wundef -Wuninitialized @gol
-Wunknown-pragmas -Wunreachable-code @gol
-Wunused -Wunused-function -Wunused-label -Wunused-parameter @gol
--Wunused-value -Wunused-variable -Wwrite-strings}
+-Wunused-value -Wunused-variable -Wwrite-strings -W64bit}
@item C-only Warning Options
@gccoptlist{-Wbad-function-cast -Wmissing-declarations @gol
@@ -2099,6 +2099,9 @@
@opindex Wcomment
Warn whenever a comment-start sequence @samp{/*} appears in a @samp{/*}
comment, or whenever a Backslash-Newline appears in a @samp{//} comment.
+
+@item -W64bit
+Warn 64-bit specific warnings even when the target is 32bit.
@item -Wformat
@opindex Wformat
More information about the Gcc-patches
mailing list