From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 5D7E33857C43; Wed, 14 Oct 2020 20:41:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5D7E33857C43 From: "msebor at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/97429] New: missing -Warray-bounds indexing past the end of a pointer to array Date: Wed, 14 Oct 2020 20:41:35 +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: 11.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: msebor at gcc dot gnu.org 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 target_milestone 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-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 14 Oct 2020 20:41:35 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D97429 Bug ID: 97429 Summary: missing -Warray-bounds indexing past the end of a pointer to array Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: msebor at gcc dot gnu.org Target Milestone: --- The out of bounds index in fa(), ga(), and fp() is diagnosed as expected by -Warray-bounds but the same bug in gp() is not. They all should be. $ cat xx.c && gcc -O2 -S -Wall xx.c int fa (int a[3][5]) {=20 return a[3][5]; // warning (good) } int ga (int a[3][5]) { int *p =3D &a[0][0]; return p[15]; // warning (good) } int fp (int (*pa)[3][5]) { return (*pa)[3][5]; // warning (good) } int gp (int (*pa)[3][5]) { int *p =3D &(*pa)[0][0]; // missing warning return p[15]; } xx.c: In function =E2=80=98fa=E2=80=99: xx.c:3:14: warning: array subscript 5 is above array bounds of =E2=80=98int= [5]=E2=80=99 [-Warray-bounds] 3 | return a[3][5]; // warning (good) | ~~~~^~~ xx.c:1:13: note: while referencing =E2=80=98a=E2=80=99 1 | int fa (int a[3][5]) | ~~~~^~~~~~~ xx.c: In function =E2=80=98ga=E2=80=99: xx.c:9:11: warning: array subscript 15 is outside array bounds of =E2=80=98= int[3]=E2=80=99 [-Warray-bounds] 9 | return p[15]; // warning (good) | ~^~~~ xx.c:6:13: note: while referencing =E2=80=98a=E2=80=99 6 | int ga (int a[3][5]) | ~~~~^~~~~~~ xx.c: In function =E2=80=98fp=E2=80=99: xx.c:15:18: warning: array subscript 5 is above array bounds of =E2=80=98in= t[5]=E2=80=99 [-Warray-bounds] 15 | return (*pa)[3][5]; // warning (good) | ~~~~~~~~^~~ xx.c:13:15: note: while referencing =E2=80=98pa=E2=80=99 13 | int fp (int (*pa)[3][5]) | ~~~~~~^~~~~~~~~=