https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66974
Bug ID: 66974 Summary: -Warray-bounds false positive with -O3 Product: gcc Version: 5.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: gajjanagadde at gmail dot com CC: gajjanagadde at gmail dot com Target Milestone: --- Created attachment 36039 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=36039&action=edit gcc_warraybounds_false.i Compiling the following code on GCC 5.2.0 produces a bogus out of bounds warning at -O3 level: ------- int foo(unsigned order) { int c[3] = {1, 2, 3}; unsigned i, j; for (i = 1; i < order; i++) { for (j = 0; j < i / 2; j++) { c[j] += c[i] * c[i-j-1]; c[i-j-1] += c[i] * c[j]; } } return c[0]; } ---------------------- %gcc -Warray-bounds -O3 -c gcc_warraybounds_false.c gcc_warraybounds_false.c: In function ‘foo’: gcc_warraybounds_false.c:6:22: warning: array subscript is above array bounds [-Warray-bounds] c[j] += c[i] * c[i-j-1]; ^ gcc_warraybounds_false.c:7:26: warning: array subscript is above array bounds [-Warray-bounds] c[i-j-1] += c[i] * c[j]; ^ gcc_warraybounds_false.c:6:22: warning: array subscript is above array bounds [-Warray-bounds] c[j] += c[i] * c[i-j-1]; ^ gcc_warraybounds_false.c:6:29: warning: array subscript is above array bounds [-Warray-bounds] c[j] += c[i] * c[i-j-1]; ^ gcc_warraybounds_false.c:7:22: warning: array subscript is above array bounds [-Warray-bounds] c[i-j-1] += c[i] * c[j]; ^ gcc_warraybounds_false.c:7:26: warning: array subscript is above array bounds [-Warray-bounds] c[i-j-1] += c[i] * c[j]; ^ gcc_warraybounds_false.c:7:22: warning: array subscript is above array bounds [-Warray-bounds] c[i-j-1] += c[i] * c[j]; ----------------------- config: Using built-in specs. COLLECT_GCC=/usr/bin/gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-unknown-linux-gnu/5.2.0/lto-wrapper Target: x86_64-unknown-linux-gnu Configured with: /build/gcc/src/gcc-5.2.0/configure --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/ --enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-shared --enable-threads=posix --enable-libmpx --with-system-zlib --with-isl --enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch --disable-libssp --enable-gnu-unique-object --enable-linker-build-id --enable-lto --enable-plugin --enable-install-libiberty --with-linker-hash-style=gnu --enable-gnu-indirect-function --disable-multilib --disable-werror --enable-checking=release --with-default-libstdcxx-abi=gcc4-compatible Thread model: posix gcc version 5.2.0 (GCC)