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

           Summary: pointless warning with -Wstrict-overflow
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: br...@clisp.org


Created attachment 24429
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=24429
test case

When -Wstrict-overflow is used, gcc reports a warning
"assuming pointer wraparound does not occur when comparing P +- C1 with P +-
C2"
on a location where
1) gcc ought to be able to infer that there is no wraparound.
2) gcc emits this warning only when a certain other function is present in
   the same compilation unit.

How to reproduce:

$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/data/arch/x86-linux/gnu-inst-gcc/4.6.0/bin/../libexec/gcc/i686-pc-linux-gnu/4.6.0/lto-wrapper
Target: i686-pc-linux-gnu
Configured with: ../gcc-4.6.0/configure --build=i686-pc-linux-gnu
--host=i686-pc-linux-gnu --target=i686-pc-linux-gnu
--prefix=/arch/x86-linux/gnu-inst-gcc/4.6.0 --enable-shared
--enable-version-specific-runtime-libs --enable-nls --enable-threads=posix
--enable-__cxa_atexit --with-as=/arch/x86-linux/gnu/bin/as32
--with-gmp=/arch/x86-linux/gnu-inst-gcc/4.6.0
--with-mpfr=/arch/x86-linux/gnu-inst-gcc/4.6.0
--with-mpc=/arch/x86-linux/gnu-inst-gcc/4.6.0
--with-libelf=/arch/x86-linux/gnu-inst-gcc/4.6.0
--with-ecj-jar=/gfs/petix/Volumes/ExtData/source/gnu/gcc/sourceware.org-ecj/ecj-latest.jar
Thread model: posix
gcc version 4.6.0 (GCC) 

$ gcc -Wstrict-overflow -O2 -S foo.c
foo.c: In function 'yylex':
foo.c:2026:18: warning: assuming pointer wraparound does not occur when
comparing P +- C1 with P +- C2 [-Wstrict-overflow]
foo.c: In function 'yyparse':
foo.c:1442:6: warning: assuming pointer wraparound does not occur when
comparing P +- C1 with P +- C2 [-Wstrict-overflow]
foo.c:1442:6: warning: assuming pointer wraparound does not occur when
comparing P +- C1 with P +- C2 [-Wstrict-overflow]
foo.c:2026:18: warning: assuming pointer wraparound does not occur when
comparing P +- C1 with P +- C2 [-Wstrict-overflow]
foo.c:1407:1: warning: assuming pointer wraparound does not occur when
comparing P +- C1 with P +- C2 [-Wstrict-overflow]
foo.c:2026:18: warning: assuming pointer wraparound does not occur when
comparing P +- C1 with P +- C2 [-Wstrict-overflow]
foo.c:2026:18: warning: assuming pointer wraparound does not occur when
comparing P +- C1 with P +- C2 [-Wstrict-overflow]
foo.c:1442:6: warning: assuming pointer wraparound does not occur when
comparing P +- C1 with P +- C2 [-Wstrict-overflow]
foo.c:2026:18: warning: assuming pointer wraparound does not occur when
comparing P +- C1 with P +- C2 [-Wstrict-overflow]

1) Line 2026 contains the expression
  (p < buff + sizeof buff - 1)
but buff is an array of constant size, sizeof buff is 20.
gcc ought to be able to infer that (buff + 19) does not wrap around.

2) If the function yyparse is removed from foo.c, the warning disappears.
So apparently the warning is generated when inlining yylex into yyparse.
It makes no sense to have no warning in yylex by itself but have a warning
when it gets inlined.

Reply via email to