From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 3A7ED3858024; Wed, 10 Mar 2021 00:58:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3A7ED3858024 From: "msebor at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/99502] New: missing -Warray-bounds on partial out of bounds access in C++ Date: Wed, 10 Mar 2021 00:58:37 +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, 10 Mar 2021 00:58:37 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D99502 Bug ID: 99502 Summary: missing -Warray-bounds on partial out of bounds access in C++ 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 program below triggers two instances of -Warray-bounds when compiled as= C code but only one when compiled as C++. This is a regression introduced in= =20 r11-7563. $ cat u.C && gcc -O2 -S -Wall u.C typedef struct A { int i; } A; char a[sizeof (A) - 1]; void f (A x) { A *p =3D (A*)a; *p =3D x; // -Warray-bounds (good) } void g (void) { A *p =3D (A*)a; p->i =3D 0; // missing warning in C++ } u.C: In function =E2=80=98void f(A)=E2=80=99: u.C:8:6: warning: array subscript =E2=80=98A[0]=E2=80=99 is partly outside = array bounds of =E2=80=98char [3]=E2=80=99 [-Warray-bounds] 8 | *p =3D x; // -Warray-bounds (good) | ~~~^~~ u.C:3:6: note: while referencing =E2=80=98a=E2=80=99 3 | char a[sizeof (A) - 1]; | ^=