Bug 32102 - -Wall stomps on -Wstrict-overflow
: -Wall stomps on -Wstrict-overflow
Status: RESOLVED FIXED
Product: gcc
Classification: Unclassified
Component: c
: 4.3.0
: P3 normal
: 4.2.3
Assigned To: Not yet assigned to anyone
: http://gcc.gnu.org/ml/gcc-patches/200...
:
:
:
  Show dependency treegraph
 
Reported: 2007-05-27 02:46 UTC by Michael Elizabeth Chastain
Modified: 2008-01-27 18:39 UTC (History)
4 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2008-01-18 19:02:48


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Elizabeth Chastain 2007-05-27 02:46:29 UTC
This is with the 4.3-20070525 snapshot.

Test program:

void Alpha();

void Beta() {
  int i;
  for (i = 1; i > 0; ++i)
    Alpha();
}

This invocation produces no warnings:

/home/mec/gcc-4.3-20070525/install/bin/gcc -O2 -S -Wstrict-overflow=2 -Wall
z1.c

This invocation produces warnings:

/home/mec/gcc-4.3-20070525/install/bin/gcc -O2 -S -Wall -Wstrict-overflow=2
z1.c
z1.c: In function 'Beta':
z1.c:5: warning: assuming signed overflow does not occur when simplifying
conditional to constant

It looks like -Wall sets the strict overflow warning level to 1, quietly
stomping on the earlier setting.
Comment 1 Andrew Pinski 2007-05-27 03:45:06 UTC
I don't think this is a bug, -Wall enable -Wstrict-overflow=1 so you have
-Wstrict-overflow=2 -Wstrict-overflow=1 (-Wstrict-overflow is the same as
-Wstrict-overflow=2).  This is just like any other option like -fno-tree-vrp
-O2.
Comment 2 Ian Lance Taylor 2007-05-29 13:48:38 UTC
I think that having -Wall clobber -Wstrict-overflow in this way is confusing. 
This isn't reversing the setting of the option, it's changing its level.
Comment 3 Manuel López-Ibáñez 2008-01-18 18:44:24 UTC
*** Bug 34843 has been marked as a duplicate of this bug. ***
Comment 4 İsmail "cartman" Dönmez 2008-01-18 18:46:17 UTC
I think then -Wall shouldn't enable -Wstrict-overflow at all. Because current
situation is counter intuitive.
Comment 5 Manuel López-Ibáñez 2008-01-18 19:02:48 UTC
(In reply to comment #4)
> I think then -Wall shouldn't enable -Wstrict-overflow at all. Because current
> situation is counter intuitive.
> 

This a bug. A quick fix is:

Index: gcc/c-opts.c
===================================================================
--- gcc/c-opts.c        (revision 131530)
+++ gcc/c-opts.c        (working copy)
@@ -403,7 +403,8 @@
       warn_switch = value;
       set_Wstrict_aliasing (value);
       warn_address = value;
-      warn_strict_overflow = value;
+      if (warn_strict_overflow < 2)
+        warn_strict_overflow = value;
       warn_array_bounds = value;

       /* Only warn about unknown pragmas that are not in system

As you can see above, the same happens for other options, e.g.,
-Wstrict-aliasing=2 -Wall.

My proposal to fix this is here: 
http://gcc.gnu.org/ml/gcc/2007-05/msg00719.html
http://gcc.gnu.org/ml/gcc/2007-05/msg00724.html
Comment 6 İsmail "cartman" Dönmez 2008-01-18 19:11:02 UTC
Manu,

Your fix looks quite obvious, could you send it to gcc-patches so we can fix
this before the freeze? Thanks for the quick fix btw.

Regards,
ismail
Comment 7 Manuel López-Ibáñez 2008-01-19 01:40:13 UTC
(In reply to comment #6)
> 
> Your fix looks quite obvious, could you send it to gcc-patches so we can fix
> this before the freeze? Thanks for the quick fix btw.
> 

That fix is too simple. It doesn't handle -Wno-strict-overflow -Wall, for
example. It also needs testcases.

I am testing a better patch.
Comment 8 Manuel López-Ibáñez 2008-01-20 13:38:28 UTC
(In reply to comment #2)
> I think that having -Wall clobber -Wstrict-overflow in this way is confusing. 
> This isn't reversing the setting of the option, it's changing its level.
> 

Ian, should the above testcase actually give a warning? I am testing revision
131656 and I cannot get a warning no matter what value of -Wstrict-overflow or
optimisation level I try.
Comment 9 Manuel López-Ibáñez 2008-01-21 01:10:32 UTC
*** Bug 34841 has been marked as a duplicate of this bug. ***
Comment 10 Ian Lance Taylor 2008-01-21 20:40:32 UTC
This test case will give a warning with mainline with -Wstrict-overflow (aka
-Wstrict-overflow=2) but not with -Wall (which implies -Wstrict-overflow=1).

void Alpha();

void Beta() {
  int i;
  for (i = 1; i > 0; i += i)
    Alpha();
}
Comment 11 Manuel López-Ibáñez 2008-01-21 20:54:29 UTC
(In reply to comment #10)
> This test case will give a warning with mainline with -Wstrict-overflow (aka
> -Wstrict-overflow=2) but not with -Wall (which implies -Wstrict-overflow=1).
> 

I think that testcase is structurally equivalent to the one I have included in
my proposed (and unreviewed, ;-) patch.
Comment 12 Manuel López-Ibáñez 2008-01-22 14:12:31 UTC
Subject: Bug 32102

Author: manu
Date: Tue Jan 22 14:11:44 2008
New Revision: 131720

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=131720
Log:
2008-01-22  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>

        PR 32102
        * doc/invoke.texi (-Wall): -Wall enables -Wstrict-overflow=1.
        * 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.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/c-opts.c
    trunk/gcc/common.opt
    trunk/gcc/doc/invoke.texi
    trunk/gcc/flags.h
    trunk/gcc/opts.c
    trunk/gcc/testsuite/ChangeLog
Comment 13 Manuel López-Ibáñez 2008-01-22 14:19:47 UTC
Subject: Bug 32102

Author: manu
Date: Tue Jan 22 14:19:01 2008
New Revision: 131722

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=131722
Log:
Missed testcases in earlier commit.

2008-01-22  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>

    PR 32102
testsuite/
    * gcc.dg/Wstrict-overflow-21.c: New.
    * g++.dg/warn/Wstrict-aliasing-8.C: New.

Added:
    trunk/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-8.C
    trunk/gcc/testsuite/gcc.dg/Wstrict-overflow-21.c
Comment 14 Manuel López-Ibáñez 2008-01-22 14:22:09 UTC
When you try to do things faster, you end up taking more time.

Anyway, fixed for GCC 4.3.

Ian, 

do you think this should/could be backported to GCC 4.2 or should we just close
it as fixed?
Comment 15 Ian Lance Taylor 2008-01-23 05:21:09 UTC
I would be in favor of backporting to the gcc 4.2 branch.  The option is new in
gcc 4.2, and this will make it less confusing to use.
Comment 16 Manuel López-Ibáñez 2008-01-27 18:37:46 UTC
Subject: Bug 32102

Author: manu
Date: Sun Jan 27 18:36:59 2008
New Revision: 131887

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=131887
Log:
2008-01-27  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.

Added:
    branches/gcc-4_2-branch/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-8.C
    branches/gcc-4_2-branch/gcc/testsuite/gcc.dg/Wstrict-overflow-21.c
Modified:
    branches/gcc-4_2-branch/gcc/ChangeLog
    branches/gcc-4_2-branch/gcc/c-opts.c
    branches/gcc-4_2-branch/gcc/common.opt
    branches/gcc-4_2-branch/gcc/flags.h
    branches/gcc-4_2-branch/gcc/opts.c
    branches/gcc-4_2-branch/gcc/testsuite/ChangeLog
Comment 17 Manuel López-Ibáñez 2008-01-27 18:39:15 UTC
Fixed in GCC 4.2.3