From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 9F51A3858C2D; Mon, 3 Apr 2023 20:29:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9F51A3858C2D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1680553782; bh=6ABC2xzT6Dy2ms3P9nmqDUuMSOstEWDH5QnF03pux9w=; h=From:To:Subject:Date:In-Reply-To:References:From; b=gdZx6BRF6zez8Axd0FOXEGQ3FooruJ2WlK83a8XxHkmo7eygKgneNYTZlKLI7YwSN R3ZTl8qUxZQ9bnbIKroRwowxEXsRDVCe99tIP7gEZAyRvxiLLJVRGL+ksL97SqTPMB Z61RofK9WS1/C9nLBN/iCSDM4yFBIqRUTZ42QIDw= 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: Mon, 03 Apr 2023 20:29:41 +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 #35 from qinzhao at gcc dot gnu.org --- (In reply to Martin Uecker from comment #34) > Created attachment 54787 [details] > patch for C FE to add size expressions to VM types in structs thanks a lot for the patch. could you please provide a small testing case that works with this patch th= at I can take a further look? I tried very simple one, didn't compile: struct P { int k; int x[.k]; }; void foo (int n) { struct P p; p.k =3D n; return; } >=20 > It works with UBSan, but it isn't clear how this could pass the > information to the object size pass. This also does not work for > parameters: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D109334 >From your change, I can see that you put the ".k" info to the index of the array type for x[.k], so I guess that other passes can refer the index of t= he array type to get the max size of this array. >=20 > So it seems for an attribute it might make sense to implement > it differently. implement should be different. but the functionality of the user interface = is better to be kept consistent between attribute and language extension. i.e in addition to the basic: struct P { int k; int x[.k]; }; will you support expressions: struct P { int k; int x[.k * 4]; } ? or other more complicated syntax?=