This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Add warning flag for undefined behavior
- From: Richard Guenther <rguenth at tat dot physik dot uni-tuebingen dot de>
- To: gcc-patches at gcc dot gnu dot org
- Date: Thu, 09 Jun 2005 17:18:47 +0200
- Subject: [PATCH] Add warning flag for undefined behavior
A fallout from my tries at implementing sseregparm attribute. No longer
used for that, but useful elsewhere.
This adds -Wundefined, default on, for stuff that invokes undefined
behavior like calls we transform to abort() (see c-typeck.c) or ABI
mismatches I used this on in i386.c.
No testcase, not bootstrapped (but compiled and checked that it works
in i386.c) - just that it doesn't get lost.
Ok for mainline anyway?
Thanks,
Richard.
2005-06-09 Richard Guenther <rguenth@gcc.gnu.org>
* common.opt (Wundefined): New flag for warning for
undefined behavior, default on.
* config/i386/i386.c (function_arg): Use.
(ix86_struct_value_rtx): Likewise.
* doc/invoke.texi: Document.
Index: common.opt
===================================================================
RCS file: /cvs/gcc/gcc/gcc/common.opt,v
retrieving revision 1.73
diff -c -3 -p -r1.73 common.opt
*** common.opt 4 Jun 2005 17:07:55 -0000 1.73
--- common.opt 9 Jun 2005 15:09:30 -0000
*************** Wsystem-headers
*** 133,138 ****
--- 133,142 ----
Common Var(warn_system_headers)
Do not suppress warnings from system headers
+ Wundefined
+ Common Var(warn_undefined) Init(1)
+ Warn about code that invokes undefined behavior
+
Wuninitialized
Common Var(warn_uninitialized)
Warn about uninitialized automatic variables
Index: config/i386/i386.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/i386/i386.c,v
retrieving revision 1.827
diff -c -3 -p -r1.827 i386.c
*** config/i386/i386.c 9 Jun 2005 03:53:20 -0000 1.827
--- config/i386/i386.c 9 Jun 2005 15:10:07 -0000
*************** function_arg (CUMULATIVE_ARGS *cum, enum
*** 2927,2934 ****
if (!TARGET_SSE && !warnedsse && cum->warn_sse)
{
warnedsse = true;
! warning (0, "SSE vector argument without SSE enabled "
! "changes the ABI");
}
if (cum->sse_nregs)
ret = gen_reg_or_parallel (mode, orig_mode,
--- 3004,3011 ----
if (!TARGET_SSE && !warnedsse && cum->warn_sse)
{
warnedsse = true;
! warning (OPT_Wundefined, "SSE vector argument without "
! "SSE enabled changes the ABI");
}
if (cum->sse_nregs)
ret = gen_reg_or_parallel (mode, orig_mode,
*************** function_arg (CUMULATIVE_ARGS *cum, enum
*** 2944,2951 ****
if (!TARGET_MMX && !warnedmmx && cum->warn_mmx)
{
warnedmmx = true;
! warning (0, "MMX vector argument without MMX enabled "
! "changes the ABI");
}
if (cum->mmx_nregs)
ret = gen_reg_or_parallel (mode, orig_mode,
--- 3021,3028 ----
if (!TARGET_MMX && !warnedmmx && cum->warn_mmx)
{
warnedmmx = true;
! warning (OPT_Wundefined, "MMX vector argument without "
! "MMX enabled changes the ABI");
}
if (cum->mmx_nregs)
ret = gen_reg_or_parallel (mode, orig_mode,
*************** ix86_struct_value_rtx (tree type, int in
*** 3197,3203 ****
|| (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 16))
{
warned = true;
! warning (0, "SSE vector return without SSE enabled changes the ABI");
}
}
--- 3274,3281 ----
|| (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 16))
{
warned = true;
! warning (OPT_Wundefined, "SSE vector return without SSE "
! "enabled changes the ABI");
}
}
Index: doc/invoke.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/invoke.texi,v
retrieving revision 1.632
diff -c -3 -p -r1.632 invoke.texi
*** doc/invoke.texi 6 Jun 2005 02:32:27 -0000 1.632
--- doc/invoke.texi 9 Jun 2005 15:11:09 -0000
*************** Objective-C and Objective-C++ Dialects}.
*** 240,246 ****
-Wreturn-type -Wsequence-point -Wshadow @gol
-Wsign-compare -Wstrict-aliasing -Wstrict-aliasing=2 @gol
-Wswitch -Wswitch-default -Wswitch-enum @gol
! -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 @gol
--- 240,246 ----
-Wreturn-type -Wsequence-point -Wshadow @gol
-Wsign-compare -Wstrict-aliasing -Wstrict-aliasing=2 @gol
-Wswitch -Wswitch-default -Wswitch-enum @gol
! -Wsystem-headers -Wtrigraphs -Wundef -Wno-undefined -Wuninitialized @gol
-Wunknown-pragmas -Wunreachable-code @gol
-Wunused -Wunused-function -Wunused-label -Wunused-parameter @gol
-Wunused-value -Wunused-variable -Wwrite-strings @gol
*************** In order to get a warning about an unuse
*** 2614,2619 ****
--- 2614,2624 ----
either specify @samp{-Wextra -Wunused} (note that @samp{-Wall} implies
@samp{-Wunused}), or separately specify @option{-Wunused-parameter}.
+ @item -Wno-undefined
+ @opindex Wno-undefined
+ Do not warn about code that invokes undefined behavior. Such code may be
+ transformed to runtime @code{abort} calls by the compiler.
+
@item -Wuninitialized
@opindex Wuninitialized
Warn if an automatic variable is used without first being initialized or