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: unassig...@gcc.gnu.org ReportedBy: egg...@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'