From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 7383B3858436; Thu, 2 Mar 2023 15:50:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7383B3858436 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1677772237; bh=6N0Bvgtf1HHSB94TS8vH/eWgeQllxHSGryGF47Z45SI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=khi39o0jkJ3PiOk28sdLbCj5t0Yvs6bfEvWx2zN6GGNG0jeRy3GWmre+SvVQqtC3G lt9rVsc8bCFtY+nFKGqZuXkrZFUZx1miBDWuNcZZxPnNsFP0Y2YtdipDEDsONt0OLL 3PMCsD6PwM5D10biLm0btSUzgCd88SVU2koE7kVc= From: "muecker at gwdg dot de" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/108896] provide "element_count" attribute to give more context to __builtin_dynamic_object_size() and -fsanitize=bounds Date: Thu, 02 Mar 2023 15:50:36 +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: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: enhancement X-Bugzilla-Who: muecker at gwdg dot de 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=3D108896 --- Comment #7 from Martin Uecker --- An attribute is certainly simpler and should be easy to add. I proposed similar extension for C23 and there was some interest, but I did not have time to follow up. https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2660.pdf Sizeof is not a constant expression in ISO C for a VLA and it is not a cons= tant expression if the struct contains a VLA (GNU extension). So this is alrea= dy the case and nothing would need to change. It would also potentially avoid mistakes when computing the size of such a struct. But the rules for initialization are not so clear. I do not think it is a good idea to differentiate between file scope structs and others. This would be confusing.=20 Considering that the GNU extensions is rarely used, one could consider redefining the meaning of int n =3D 1; struct { int n; char buf[n]; }; so that the 'n' refers to the member. Or we add a new syntax similar to designators (which intuitively makes sense to me).=