This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[4.2] PR32102 -Wall stomps on -Wstrict-overflow and -Wstrict-aliasing
- From: "Manuel López-Ibáñez" <lopezibanez at gmail dot com>
- To: "GCC Patches" <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 24 Jan 2008 15:12:31 +0100
- Subject: [4.2] PR32102 -Wall stomps on -Wstrict-overflow and -Wstrict-aliasing
This patch prevents -Wall from overriding the value of an explicit
-Wstrict-overflow option (similarly for -Wstrict-aliasing).
Bootstrapped with --enable-languages=all --disable-multilib
and regression tested on x86_64-unknown-linux-gnu
OK to commit to 4.2 branch?
2008-01-24 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
PR 32102
* flags.h (warn_strict_aliasing): Remove.
(warn_strict_overflow): Remove.
* opts.c (warn_strict_aliasing): Remove.
(warn_strict_overflow): Remove.
* c-opts.c (c_common_handle_option): -Wall only sets
-Wstrict-aliasing or -Wstrict-overflow if they are uninitialized.
(c_common_post_options): Give default values to -Wstrict-aliasing
and -Wstrict-overflow if they are uninitialized.
* common.opt (Wstrict-aliasing): Specify Var and Init.
(Wstrict-overflow): Likewise.
testsuite/
* gcc.dg/Wstrict-overflow-21.c: New.
* g++.dg/warn/Wstrict-aliasing-8.C: New.
Index: gcc/flags.h
===================================================================
--- gcc/flags.h (revision 131745)
+++ gcc/flags.h (working copy)
@@ -106,20 +106,10 @@ extern void set_Wunused (int setting);
values are larger than N bytes. The value N is in `larger_than_size'. */
extern bool warn_larger_than;
extern HOST_WIDE_INT larger_than_size;
-/* Nonzero means warn about constructs which might not be strict
- aliasing safe. */
-
-extern int warn_strict_aliasing;
-
-/* Nonzero means warn about optimizations which rely on undefined
- signed overflow. */
-
-extern int warn_strict_overflow;
-
/* Temporarily suppress certain warnings.
This is set while reading code from a system header file. */
extern int in_system_header;
Index: gcc/testsuite/gcc.dg/Wstrict-overflow-21.c
===================================================================
--- gcc/testsuite/gcc.dg/Wstrict-overflow-21.c (revision 0)
+++ gcc/testsuite/gcc.dg/Wstrict-overflow-21.c (revision 0)
@@ -0,0 +1,10 @@
+/* PR 32102: -Wall stomps on -Wstrict-overflow */
+/* { dg-do compile } */
+/* { dg-options "-fstrict-overflow -O2 -Wstrict-overflow=2 -Wall" } */
+int
+foo (int i)
+{
+ return __builtin_abs (i) >= 0; /* { dg-warning "assuming signed overflow does not occur" "correct warning" } */
+}
+
+
Index: gcc/testsuite/g++.dg/warn/Wstrict-aliasing-8.C
===================================================================
--- gcc/testsuite/g++.dg/warn/Wstrict-aliasing-8.C (revision 0)
+++ gcc/testsuite/g++.dg/warn/Wstrict-aliasing-8.C (revision 0)
@@ -0,0 +1,20 @@
+/* { dg-do compile } */
+/* { dg-options "-Wstrict-aliasing=2 -O2 -Wall" } */
+
+int a[2];
+
+double *foo1(void)
+{
+ return (double *)a; /* { dg-warning "strict-aliasing" } */
+}
+
+double *foo2(void)
+{
+ return (double *)&a[0]; /* { dg-warning "strict-aliasing" } */
+}
+
+__complex__ double x;
+int *bar(void)
+{
+ return (int *)&__imag__ x; /* { dg-warning "strict-aliasing" } */
+}
Index: gcc/opts.c
===================================================================
--- gcc/opts.c (revision 131745)
+++ gcc/opts.c (working copy)
@@ -54,18 +54,10 @@ bool extra_warnings;
than N bytes. Also want about function definitions whose returned
values are larger than N bytes, where N is `larger_than_size'. */
bool warn_larger_than;
HOST_WIDE_INT larger_than_size;
-/* Nonzero means warn about constructs which might not be
- strict-aliasing safe. */
-int warn_strict_aliasing;
-
-/* Nonzero means warn about optimizations which rely on undefined
- signed overflow. */
-int warn_strict_overflow;
-
/* Hack for cooperation between set_Wunused and set_Wextra. */
static bool maybe_warn_unused_parameter;
/* Type(s) of debugging information we are producing (if any). See
flags.h for the definitions of the different possible types of
Index: gcc/c-opts.c
===================================================================
--- gcc/c-opts.c (revision 131745)
+++ gcc/c-opts.c (working copy)
@@ -1,7 +1,7 @@
/* C/ObjC/C++ command line option handling.
- Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007
+ Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008
Free Software Foundation, Inc.
Contributed by Neil Booth.
This file is part of GCC.
@@ -390,12 +390,14 @@ c_common_handle_option (size_t scode, co
warn_return_type = value;
warn_sequence_point = value; /* Was C only. */
if (c_dialect_cxx ())
warn_sign_compare = value;
warn_switch = value;
- warn_strict_aliasing = value;
- warn_strict_overflow = value;
+ if (warn_strict_aliasing == -1)
+ warn_strict_aliasing = value;
+ if (warn_strict_overflow == -1)
+ warn_strict_overflow = value;
warn_address = value;
/* Only warn about unknown pragmas that are not in system
headers. */
warn_unknown_pragmas = value;
@@ -1034,10 +1036,15 @@ c_common_post_options (const char **pfil
/* -Wpointer_sign is disabled by default, but it is enabled if any
of -Wall or -pedantic are given. */
if (warn_pointer_sign == -1)
warn_pointer_sign = 0;
+ if (warn_strict_aliasing == -1)
+ warn_strict_aliasing = 0;
+ if (warn_strict_overflow == -1)
+ warn_strict_overflow = 0;
+
/* -Woverlength-strings is off by default, but is enabled by -pedantic.
It is never enabled in C++, as the minimum limit is not normative
in that standard. */
if (warn_overlength_strings == -1 || c_dialect_cxx ())
warn_overlength_strings = 0;
Index: gcc/common.opt
===================================================================
--- gcc/common.opt (revision 131745)
+++ gcc/common.opt (working copy)
@@ -127,19 +127,19 @@ Warn when not issuing stack smashing pro
Wstrict-aliasing
Common
Warn about code which might break strict aliasing rules
Wstrict-aliasing=
-Common Joined UInteger
+Common Joined UInteger Var(warn_strict_aliasing) Init(-1)
Warn about code which might break strict aliasing rules
Wstrict-overflow
Common
Warn about optimizations that assume that signed overflow is undefined
Wstrict-overflow=
-Common Joined UInteger
+Common Joined UInteger Var(warn_strict_overflow) Init(-1)
Warn about optimizations that assume that signed overflow is undefined
Wswitch
Common Var(warn_switch)
Warn about enumerated switches, with no default, missing a case