From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id B74643858C5F; Mon, 3 Apr 2023 21:53:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B74643858C5F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1680558822; bh=nv+FMgOz86+kpFV66hrFmgt/Trzn7BHXIxPZ1Cip0to=; h=From:To:Subject:Date:In-Reply-To:References:From; b=rZACk9so/+bhUBu2+noWBigvF2Z4VWvRJAWwQDyERkLJM4Czur6GkrD4AJI9zbu+W NlOF9HWNMKeAaXVYWwnp/OEQRxdSMNsOlvnFlY5ceCfbK3GDNTnSgL/Ren/3QSPdn6 cQLNjX2TNoe7J6iSeIfMS8/4DTHNdasSTuF7lfTc= 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: Mon, 03 Apr 2023 21:53:42 +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 #36 from Martin Uecker --- Am Montag, dem 03.04.2023 um 20:29 +0000 schrieb qinzhao at gcc dot gnu.org: > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D108896 >=20 > --- 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 >=20 > thanks a lot for the patch. >=20 > could you please provide a small testing case that works with this patch = that I > can take a further look? I considered pointers to arrays: struct P { int n; char (*buf)[.n]; }; the FAM case needs more work and I guess there are still many other problems with the patch. > I tried very simple one, didn't compile: >=20 > struct P { > =C2=A0=C2=A0int k; > =C2=A0=C2=A0int x[.k]; > }; >=20 > void > foo (int n) > { > =C2=A0=C2=A0struct P p; > =C2=A0=C2=A0p.k =3D n; > =C2=A0=C2=A0return; > } >=20 > >=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 >=20 > 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= the > array type to get the max size of this array. >=20 The comments in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D104970 imply that the size information does not survive long enough > >=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 interfac= e is > better to be kept consistent between attribute and language extension. i.e >=20 > in addition to the basic: >=20 > struct P { > =C2=A0=C2=A0int k; > =C2=A0=C2=A0int x[.k]; > }; >=20 > will you support expressions: >=20 > struct P { > =C2=A0=C2=A0int k; > =C2=A0=C2=A0int x[.k * 4]; > } > ? > or other more complicated syntax? I am not sure. I am still experimenting with this to gain experience. It is easy to move the parser code elsehwere and then complicated expressions can be used. But the size expression is evaluated each time when the member is accessed. Do we really want to run arbitrary code at this point?=C2=A0 Maybe the size expressions should be limited to very simple expressions without side effects. Martin >=