From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 24DD23858404; Wed, 25 Jan 2023 12:45:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 24DD23858404 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1674650701; bh=ppgGl4bGnSpb9Lvx3BVafn9omTQTc+UtFRwuPk4yL/U=; h=From:To:Subject:Date:In-Reply-To:References:From; b=ZOVAdpuPgMfmcYQwvAcRIzJYJleUDz/qZKiQrVajj6XUJSFG65WFDS/46AijhGmTe 4bo758W7yMKYHfu9bmZPhQLjPKOYuZRgOxIYM9nUcAqft7lyuJFk2vM0qSqji3/L1m Kk66xdrarO1dcvS0+EyprndfDneQDxV0X+tkaJzw= From: "siddhesh 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: Wed, 25 Jan 2023 12:44:59 +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: siddhesh 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 #12 from Siddhesh Poyarekar --- (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? There's an open bug to document these semantics: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D77650(In reply to rguenther@suse.de from comment #11) > On Tue, 24 Jan 2023, qing.zhao at oracle dot com wrote: >=20 > > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D107952 > >=20 > > --- Comment #10 from Qing Zhao --- > > > --- Comment #9 from Richard Biener --- > > >=20 > > > GCC handles for example > > >=20 > > > struct A { char data[1]; }; > > > struct B { int n; struct A a; }; > > >=20 > > > as if the a.data[] array is a flex-array. > >=20 > > Okay. Then the maximum size of __builtin_object_size for it should be -= 1, > > right? >=20 > I think so. Why? If the a B object is allocated with a visible allocator call, we can return the correct size here too.=