From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 4077C3858C50; Wed, 25 Jan 2023 21:54:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4077C3858C50 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1674683675; bh=5b0deqssEXMvAHF2W+AEMyuaJZJ3DdVO+WmX6xtSF/4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Q2L7nhDejvaJKskDE2R8hhFgnGczixbD/SbUkk51dC78/MtsA6bKSQG778KzVv6E/ JfMFy6FSjGZwpW4mleaQPzcI6GmRln6FsU0E6OiG64Jowx7Vsx3H1/Gu8pKTRsQXie MLwvnd7hTDTcdALZ+REuC1rmKw6nBJjwKA8g2UDY= From: "qinzhao at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/101832] __builtin_object_size(P->M, 1) where M ends with a flex-array behaves like sizeof() Date: Wed, 25 Jan 2023 21:54:34 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: qinzhao at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: qinzhao 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=3D101832 --- Comment #8 from qinzhao at gcc dot gnu.org --- (In reply to Jakub Jelinek from comment #3) > This is intentional, if you embed an aggregate with flex array into anoth= er > struct and ask not to cross the field boundaries (i.e. bos1), then the si= ze > of that field is exactly what is the maximum size. As we discussed in PR 107952 (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D107952): GCC extension accepts the following two cases: **Case 1: struct A { char data[1]; }; struct B { int n; struct A a; }; as if the a.data[] array is a flex-array.=20=20 **Case 2:=20 struct C { int n; struct A a; int x; }; as if a.data[] can be up to 4 elements.=20 So, what's you mean by "not to cross the field boundaries" is for the above Case 2?=20 For Case 1, we should treat A.data as flexible array, and then B.A as a structure that has flexible array, therefore B.A's size is flexible too.=20 Is my understanding correct?=