public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/50082] New: -Wstrict-overflow mishandles typedef
@ 2011-08-15  8:01 eggert at gnu dot org
  2011-08-15 11:05 ` [Bug c/50082] " rguenth at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: eggert at gnu dot org @ 2011-08-15  8:01 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50082

             Bug #: 50082
           Summary: -Wstrict-overflow mishandles typedef
    Classification: Unclassified
           Product: gcc
           Version: 4.6.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: eggert@gnu.org


Created attachment 25011
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=25011
Sample program illustrating bogus warning

(I ran into this problem when building a test version of GNU Emacs.)

"gcc -Wstrict-overflow -O2" sometimes issues a bogus warning when an
int is declared via a typedef rather than using a bare 'int' keyword.

Compile the attached file r.c with "gcc -Wstrict-overflow -O2 -S r.c".
There will be a diagnostic:

  r.c: In function 'insert_cache_boundary_bad':
  r.c:19:6: warning: assuming signed overflow does not occur when reducing
constant in comparison [-Wstrict-overflow]

r.c has two functions that are nearly identical.  The only difference
is that 'insert_cache_boundary_ok' uses plain 'int', whereas
'insert_cache_boundary_bad' uses 'foo' which is declared via "typedef
int foo;".  The ..._ok function does not produce the bogus warning,
the ..._bad function does.  (Both functions compile into the same
machine code.)

The diagnostic is bogus, since GCC can clearly deduce that signed
overflow is impossible here: 'i' must be nonnegative at the point of
the complaint, and 'i - 1' cannot possibly overflow.

For reference, here is the output of "gcc -v -save-temps
-Wstrict-overflow -O2 -S r.c".

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/home/eggert/opt/Linux-x86_64/gcc-4.6.1/libexec/gcc/x86_64-unknown-linux-gnu/4.6.1/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-4.6.1/configure
--prefix=/home/eggert/opt/Linux-x86_64/gcc-4.6.1 --disable-nls
Thread model: posix
gcc version 4.6.1 (GCC) 
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Wstrict-overflow' '-O2' '-S'
'-mtune=generic' '-march=x86-64'

/home/eggert/opt/Linux-x86_64/gcc-4.6.1/libexec/gcc/x86_64-unknown-linux-gnu/4.6.1/cc1
-E -quiet -v r.c -mtune=generic -march=x86-64 -Wstrict-overflow -O2
-fpch-preprocess -o r.i
ignoring nonexistent directory
"/home/eggert/opt/Linux-x86_64/gcc-4.6.1/lib/gcc/x86_64-unknown-linux-gnu/4.6.1/../../../../x86_64-unknown-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:

/home/eggert/opt/Linux-x86_64/gcc-4.6.1/lib/gcc/x86_64-unknown-linux-gnu/4.6.1/include
 /usr/local/include
 /home/eggert/opt/Linux-x86_64/gcc-4.6.1/include

/home/eggert/opt/Linux-x86_64/gcc-4.6.1/lib/gcc/x86_64-unknown-linux-gnu/4.6.1/include-fixed
 /usr/include
End of search list.
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Wstrict-overflow' '-O2' '-S'
'-mtune=generic' '-march=x86-64'

/home/eggert/opt/Linux-x86_64/gcc-4.6.1/libexec/gcc/x86_64-unknown-linux-gnu/4.6.1/cc1
-fpreprocessed r.i -quiet -dumpbase r.c -mtune=generic -march=x86-64 -auxbase r
-O2 -Wstrict-overflow -version -o r.s
GNU C (GCC) version 4.6.1 (x86_64-unknown-linux-gnu)
    compiled by GNU C version 4.6.1, GMP version 4.3.1, MPFR version 2.4.2, MPC
version 0.8.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU C (GCC) version 4.6.1 (x86_64-unknown-linux-gnu)
    compiled by GNU C version 4.6.1, GMP version 4.3.1, MPFR version 2.4.2, MPC
version 0.8.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: b0a4f47793c670c0e36c6193e4fd175b
r.c: In function 'insert_cache_boundary_bad':
r.c:19:6: warning: assuming signed overflow does not occur when reducing
constant in comparison [-Wstrict-overflow]
COMPILER_PATH=/home/eggert/opt/Linux-x86_64/gcc-4.6.1/libexec/gcc/x86_64-unknown-linux-gnu/4.6.1/:/home/eggert/opt/Linux-x86_64/gcc-4.6.1/libexec/gcc/x86_64-unknown-linux-gnu/4.6.1/:/home/eggert/opt/Linux-x86_64/gcc-4.6.1/libexec/gcc/x86_64-unknown-linux-gnu/:/home/eggert/opt/Linux-x86_64/gcc-4.6.1/lib/gcc/x86_64-unknown-linux-gnu/4.6.1/:/home/eggert/opt/Linux-x86_64/gcc-4.6.1/lib/gcc/x86_64-unknown-linux-gnu/
LIBRARY_PATH=/home/eggert/opt/Linux-x86_64/gcc-4.6.1/lib/gcc/x86_64-unknown-linux-gnu/4.6.1/:/home/eggert/opt/Linux-x86_64/gcc-4.6.1/lib/gcc/x86_64-unknown-linux-gnu/4.6.1/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/home/eggert/opt/Linux-x86_64/gcc-4.6.1/lib/gcc/x86_64-unknown-linux-gnu/4.6.1/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Wstrict-overflow' '-O2' '-S'
'-mtune=generic' '-march=x86-64'


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2011-08-16 15:36 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-15  8:01 [Bug c/50082] New: -Wstrict-overflow mishandles typedef eggert at gnu dot org
2011-08-15 11:05 ` [Bug c/50082] " rguenth at gcc dot gnu.org
2011-08-15 14:48 ` ian at airs dot com
2011-08-15 15:09 ` rguenth at gcc dot gnu.org
2011-08-15 15:48 ` rguenth at gcc dot gnu.org
2011-08-15 20:04 ` iant at google dot com
2011-08-16  9:19 ` rguenth at gcc dot gnu.org
2011-08-16 11:47 ` [Bug tree-optimization/50082] " rguenth at gcc dot gnu.org
2011-08-16 15:36 ` rguenth at gcc dot gnu.org
2011-08-16 16:21 ` rguenth at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).