From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 5DA193857411; Wed, 1 Sep 2021 15:02:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5DA193857411 From: "msebor at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/102151] Spurious warning by -Warray-bounds when allocating with flexible array member Date: Wed, 01 Sep 2021 15:02:17 +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: 11.2.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: msebor at gcc dot gnu.org X-Bugzilla-Status: RESOLVED X-Bugzilla-Resolution: INVALID 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 see_also bug_status resolution Message-ID: In-Reply-To: References: 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, 01 Sep 2021 15:02:17 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D102151 Martin Sebor changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |msebor at gcc dot gnu.org See Also| |https://gcc.gnu.org/bugzill | |a/show_bug.cgi?id=3D101436 Status|UNCONFIRMED |RESOLVED Resolution|--- |INVALID --- Comment #3 from Martin Sebor --- As Andrew explained, the first operand in the -> expression needs to point = to an object of the type whose member is being accessed or at least as big as = one, and the warning is designed to point out when it's not (arguably, it could = be phrased better). The following is a small test case to illustrate the warn= ing (see also pr101436 comment 2 for a similar C++ test case). $ cat pr102151.c && gcc -O2 -S -Wall pr102151.c struct S { char a, b; }; extern char c; void f (void) { struct S *p =3D &c; p->a =3D 0; } pr102151.c: In function =E2=80=98f=E2=80=99: pr102151.c:7:17: warning: initialization of =E2=80=98struct S *=E2=80=99 fr= om incompatible pointer type =E2=80=98char *=E2=80=99 [-Wincompatible-pointer-types] 7 | struct S *p =3D &c; | ^ pr102151.c:8:4: warning: array subscript =E2=80=98struct S[0]=E2=80=99 is p= artly outside array bounds of =E2=80=98char[1]=E2=80=99 [-Warray-bounds] 8 | p->a =3D 0; | ^~ pr102151.c:3:13: note: while referencing =E2=80=98c=E2=80=99 3 | extern char c; | ^=