From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 908E63858C54; Thu, 2 Mar 2023 17:34:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 908E63858C54 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1677778477; bh=d6M2ft+WV1HQDyg/buzVSV2P4SByUMYJ6b1MR7ES1IY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=FN7qeFBXJ+NEvxnAl98kL43ZEz5Apuf6glLjHnF8LpJjcVbb1RlgkT0FOnk//2SV9 +g934uho6uB6T9cTph6OymRXyeEKJ2rlcjyoOH8LniEWlTGeYS1bzPE/QddIOmkUmE gSL8o6XCUDMM4wb5j60toyiF/3b9YRAvXOevERvs= From: "qinzhao at gcc dot gnu.org" 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 17:34:37 +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: 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=3D108896 --- Comment #8 from qinzhao at gcc dot gnu.org --- (In reply to Martin Uecker from comment #7) > An attribute is certainly simpler and should be easy to add. yes. >=20 > I proposed similar extension for C23 and there was some interest, > but I did not have time to follow up. >=20 > https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2660.pdf very interesting proposal! are there any discussions on this proposal? if so, can you point me to them? >=20 >=20 > Sizeof is not a constant expression in ISO C for a VLA and it is not a > constant expression if the struct contains a VLA (GNU extension). So th= is > is already the case and nothing would need to change. It would also poten= tially=20=20 > avoid mistakes when computing the size of such a struct. agreed. However, my understanding is: VLA is only valid inside a function scope. GCC use a special SAVE_EXPR to record its size expression. and evaluated during runtime only once.=20 when this variable length concept is extended to global scope, not sure how= to implement the size expression? need some study here. > But the > rules for initialization are not so clear. shall we make this clear? >=20 > I do not think it is a good idea to differentiate between file scope stru= cts > and others. This would be confusing. Yes. agreed. this proposal basically is to extend the VLA concept from function scope to global scope. is my understanding correct? >=20 > Considering that the GNU extensions is rarely used, one could consider > redefining the meaning of >=20 > int n =3D 1; > struct { > int n; > char buf[n]; > }; >=20 > so that the 'n' refers to the member. Or we add a new syntax similar to > designators (which intuitively makes sense to me). designator might be better IMO. a question here is: for the following nested structure:=20 struct object { ... char items; ... struct inner { ... int flex[]; }; } *ptr; what kind of syntax is good to represent the upper bound of "flex" in the i= nner struct with "items" in the outer structure? any suggestion?=