From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 26EDD3858C78; Tue, 28 Nov 2023 15:19:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 26EDD3858C78 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1701184785; bh=vgtLDZ7sE2dD3S3V6h3mgU+PWBo+bxtbrpgZxGB3bDg=; h=From:To:Subject:Date:In-Reply-To:References:From; b=yRYAKLc/8BPMzENGCCiegp10+fXlLvy0btTb4FPrtYypDxg947nk4N1B1GPIvYmIu jbaAnVMZWSFvPC/iUpYqTav1nE3K79ujOC1RbELuA7PCbVey5jF0i2U4iPayGv5UHz +jGHdXh6h9bot42AAKoZL2IWZyAPBDtRc3JhfOGY= From: "muecker at gwdg dot de" To: gcc-bugs@gcc.gnu.org Subject: [Bug lto/112716] LTO optimization with struct with variable size Date: Tue, 28 Nov 2023 15:19:44 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: lto X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: alias, wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: muecker at gwdg dot de X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned 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=3D112716 --- Comment #9 from Martin Uecker --- (In reply to Richard Biener from comment #8) > (In reply to uecker from comment #7) > > > >=20 > > > Note that even without LTO when you enable inlining you'd expose two > > > different structures with two different alias-sets, possibly leading > > > to wrong-code (look at the RTL expansion dump and check alias-sets). > >=20 > > Yes, for pre C23 this is true for all structs even without VLA. > > But for C23 this changes. > >=20 > > The main case where the GNU extension is interesting and useful is > > when the VLA field is at the end. So at least for this case it would > > be nice to have a solution. >=20 > So what's the GNU extension here? VLA inside structs are not a C thing? ISO C does not currently allow VLAs or variably-modified types inside structs. So all these are GNU extensions. WG14 is thinking about allowing pointers to VLAs inside structs. struct foo { int n; char (*buf)[.n]; }; But this is a bit different because it would not depend on an external value. > I suppose if they were then C23 would make only the "abstract" types > compatible but the concrete types (actual 'n') would only be compatible > when 'n' is the same? Yes, this is how it works for other variably-modified types in C (since C99) where it is then run-time undefined behavior if 'n' turns out not to be the same. >=20 > I think the GNU extension is incomplete, IIRC you can't have >=20 > foo (int n, struct bar { int x; int a[n]; } b) -> struct bar > { > return bar; > } >=20 > and there's no way to 'declare' bar in a way that it's usable across > functions. You could declare it again in another function void xyz(int n) { struct bar { int x; int a[n]; } y; foo(n, y); } and with C23 compatibility rules this would work.=20 >=20 > So I'm not sure assigning C23 "semantics" to this extension is very > useful. Your examples are awkward workarounds for an incomplete > language extension. In any case, we already have the extension and we should either we make it more useful, or document its limitations,=20 or deprecate it completely.=