From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32885 invoked by alias); 23 Jul 2015 02:52:57 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 32864 invoked by uid 48); 23 Jul 2015 02:52:52 -0000 From: "gajjanagadde at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/66974] New: -Warray-bounds false positive with -O3 Date: Thu, 23 Jul 2015 02:52:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 5.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: gajjanagadde at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter cc target_milestone attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2015-07/txt/msg01950.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D66974 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=3D36039&action=3Dedit 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] =3D {1, 2, 3}; unsigned i, j; for (i =3D 1; i < order; i++) { for (j =3D 0; j < i / 2; j++) { c[j] +=3D c[i] * c[i-j-1]; c[i-j-1] +=3D c[i] * c[j]; } } return c[0]; } ---------------------- %gcc -Warray-bounds -O3 -c gcc_warraybounds_false.c gcc_warraybounds_false.c: In function =E2=80=98foo=E2=80=99: gcc_warraybounds_false.c:6:22: warning: array subscript is above array boun= ds [-Warray-bounds] c[j] +=3D c[i] * c[i-j-1]; ^ gcc_warraybounds_false.c:7:26: warning: array subscript is above array boun= ds [-Warray-bounds] c[i-j-1] +=3D c[i] * c[j]; ^ gcc_warraybounds_false.c:6:22: warning: array subscript is above array boun= ds [-Warray-bounds] c[j] +=3D c[i] * c[i-j-1]; ^ gcc_warraybounds_false.c:6:29: warning: array subscript is above array boun= ds [-Warray-bounds] c[j] +=3D c[i] * c[i-j-1]; ^ gcc_warraybounds_false.c:7:22: warning: array subscript is above array boun= ds [-Warray-bounds] c[i-j-1] +=3D c[i] * c[j]; ^ gcc_warraybounds_false.c:7:26: warning: array subscript is above array boun= ds [-Warray-bounds] c[i-j-1] +=3D c[i] * c[j]; ^ gcc_warraybounds_false.c:7:22: warning: array subscript is above array boun= ds [-Warray-bounds] c[i-j-1] +=3D c[i] * c[j]; ----------------------- config: Using built-in specs. COLLECT_GCC=3D/usr/bin/gcc COLLECT_LTO_WRAPPER=3D/usr/lib/gcc/x86_64-unknown-linux-gnu/5.2.0/lto-wrapp= er Target: x86_64-unknown-linux-gnu Configured with: /build/gcc/src/gcc-5.2.0/configure --prefix=3D/usr --libdir=3D/usr/lib --libexecdir=3D/usr/lib --mandir=3D/usr/share/man --infodir=3D/usr/share/info --with-bugurl=3Dhttps://bugs.archlinux.org/ --enable-languages=3Dc,c++,ada,fortran,go,lto,objc,obj-c++ --enable-shared --enable-threads=3Dposix --enable-libmpx --with-system-zlib --with-isl --enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=3Dgnu --disable-libstdcxx-pch --disable-libssp --enable-gnu-unique-object --enable-linker-build-id --enable-lto --enable-plugin --enable-install-libiberty --with-linker-hash-style=3Dgnu --enable-gnu-indirect-function --disable-multilib --disable-werror --enable-checking=3Drelease --with-default-libstdcxx-abi=3Dgcc4-compatible Thread model: posix gcc version 5.2.0 (GCC) >>From gcc-bugs-return-493061-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Thu Jul 23 03:06:15 2015 Return-Path: Delivered-To: listarch-gcc-bugs@gcc.gnu.org Received: (qmail 44638 invoked by alias); 23 Jul 2015 03:06:15 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Delivered-To: mailing list gcc-bugs@gcc.gnu.org Received: (qmail 44592 invoked by uid 48); 23 Jul 2015 03:06:10 -0000 From: "dj at redhat dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/66974] -Warray-bounds false positive with -O3 Date: Thu, 23 Jul 2015 03:06:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 5.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: dj at redhat dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cc Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2015-07/txt/msg01951.txt.bz2 Content-length: 630 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66974 DJ Delorie changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |dj at redhat dot com --- Comment #1 from DJ Delorie --- If elsewhere calls foo(500) you will get an actual out of bounds access. I think the warning is appropriate. Have you tried checking the value of 'order' in that function, before the loop, to validate its value? Such a check might fix your bug and silence the warning.