From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 1EDE63858C62; Tue, 4 Apr 2023 15:07:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1EDE63858C62 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1680620836; bh=pQTJ/DuyyYKOARuBJ9xAcA4tGQjOtSwaLr0o3jeYl0U=; h=From:To:Subject:Date:In-Reply-To:References:From; b=YGlVJs3zVNrK+xuWxSS43NoGEjUTaka0xpNscMeDmldUXm5NP3JAnunkAWU933WAQ zXvNuJUOANy/TFIr19ARToAXvLTlXo8NIuM9Am/rw7PxfvU0JJ+I3I38BHiMJ7IoWD QxJK+fcc8zaITW1pb4HjCTLuayWw8SnX1CKXJjR4= 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: Tue, 04 Apr 2023 15:07:14 +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 #37 from qinzhao at gcc dot gnu.org --- (In reply to Martin Uecker from comment #36) >=20 > I considered pointers to arrays: >=20 > struct P { > int n; > char (*buf)[.n]; > }; >=20 Okay.=20 Then for the field "buf", it has a pointer type, the size of this field is a compile-time constant. where in the IR do you put the ".n" (the size of the array this pointer points to). That's the place I am trying to understand f= rom your patch or from the IR dump of a working small testing case.=20 > the FAM case needs more work and I guess there are > still many other problems with the patch. >=20 For the FAM case, since the field itself is an ARRAY type, then the ".n" ca= n be naturally put to the SIZE of the type of the field.=20 Another thing I'd like to point out, for the original intention of this PR,= FAM case is more important than the pointer to array case, I think. So, should = we focus on FAM first? >=20 > The comments in > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D104970 >=20 > imply that the size information does not survive long enough need to study this a little bit more. > But the size expression is evaluated each time when the member is > accessed.=20 How to represent this in IR? > Maybe the size expressions should be limited to very simple=20 expressions without side effects. agreed. but I think we might want to focus on FAM first.=