From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 63A8D3858D33; Tue, 24 Jan 2023 10:04:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 63A8D3858D33 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1674554658; bh=2yt2RgU2tgtHjQqV8VPaqSM1yyPUQ1V4hkDF78cy9zc=; h=From:To:Subject:Date:In-Reply-To:References:From; b=kI4CbKOPwKHOcKZccEkN5W5f1O0qCSGtZ9GcyODuQL9Pug1Y2TtKsHLPvTrv0RZrB r/+t9B/i082ViyuqrR/Uc/dwSu+LnrbM3VeOCeUpnX+d/KMQGbj5Je55P0fBQIG7Y7 X5hIHOewyIfWCD5Z1yWBMKxlcIdfZ7Muad/k8KEY= From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/107952] tree-object-size: inconsistent size for flexible arrays nested in structs Date: Tue, 24 Jan 2023 10:04:15 +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: 13.0 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenth at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: siddhesh at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D107952 --- Comment #9 from Richard Biener --- (In reply to qinzhao from comment #7) > (In reply to Richard Biener from comment #1) > > GCC considered this as a flex-array.=20 >=20 > do you mean for the following example: >=20 > typedef struct { > char pad; > char data[]; > } F2; >=20 > typedef struct { > unsigned pad; > F2 flex; > } S2; >=20 > although C standard disallow the above, GCC extension treats S2.flex.data= as > a flex-array?=20 >=20 > How about: >=20 > typedef struct { > char pad; > char data[]; > } F2; >=20 > typedef struct { > F2 flex; > unsigned pad; > } S2; >=20 > do we have any documentation on this Gcc extension? GCC handles for example struct A { char data[1]; }; struct B { int n; struct A a; }; as if the a.data[] array is a flex-array. It also handles struct C { int n; struct A a; int x; }; as if a.data[] can be up to 4 elements large (we allow an array to extend flexibly to padding - but only if it is trailing). I see that's not consistently handled though. I think the [] syntax should follow the C standard as what testcases are accepted/rejected by the frontend and any extensions there should be documented (those are separate from what the former array_at_struct_end_p allowed semantically and where GCC is careful with optimization because of code out in the wild).=