From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 81414385481A; Wed, 17 Mar 2021 18:05:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 81414385481A From: "msebor at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/99632] New: missing warning accessing a trailing zero length array member of base class Date: Wed, 17 Mar 2021 18:05:49 +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, 17 Mar 2021 18:05:49 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D99632 Bug ID: 99632 Summary: missing warning accessing a trailing zero length array member of base class 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: --- -Warray-bounds triggers for the invalid access in f() and g() but not in h(= ).=20 All three should be diagnosed. In addition, the warning in g() should be on the line with the access. $ cat t.C && gcc -O2 -S -Wall t.C struct D: B { int j; }; void f (D *p, int i) { p->a[i] =3D 0; // -Warray-bounds (good) } void g (D *p, int i) { int *q =3D &p->a[i]; //-Warray-bounds (should be on next line) *q =3D 0;=20 } void h (D *p, int i) { int *q =3D p->a; q[i] =3D 0; // missing warning } t.C: In function =E2=80=98void f(D*, int)=E2=80=99: t.C:6:9: warning: array subscript i is outside array bounds of =E2=80=98int= [0]=E2=80=99 [-Warray-bounds] 6 | p->a[i] =3D 0; // -Warray-bounds (good) | ~~~~~~^ t.C:1:19: note: while referencing =E2=80=98B::a=E2=80=99 1 | struct B { int n, a[0]; }; | ^ t.C: In function =E2=80=98void g(D*, int)=E2=80=99: t.C:11:19: warning: array subscript i is outside array bounds of =E2=80=98i= nt [0]=E2=80=99 [-Warray-bounds] 11 | int *q =3D &p->a[i]; //-Warray-bounds (should be on next line) | ~~~~~~^ t.C:1:19: note: while referencing =E2=80=98B::a=E2=80=99 1 | struct B { int n, a[0]; }; | ^=