From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 9827A3858D37; Tue, 23 May 2023 17:46:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9827A3858D37 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1684864017; bh=PAgO6wpoScr08ZXd1qFVM3vE5AEZQ3/6L/Fc2gADsJI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=sF92vTtGW/uHSIsSJKHnrmiDNLgNd7iBEn2EjditnyRF3MEjQW16J+fTopxh5c/U4 DNmPef7bmUxu138owyNVerrAreGdnZAL5aLTIvcR6GEEQt18cslZGX2s9xiyUNxDaR DgKYi9oslLcTk5wVChlQayiv0uQqn7JA79wdTLgI= From: "arthur.j.odwyer at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/109945] Escape analysis hates copy elision: different result with -O1 vs -O2 Date: Tue, 23 May 2023 17:46:56 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: arthur.j.odwyer at gmail dot com X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: rguenth 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=3D109945 --- Comment #7 from Arthur O'Dwyer --- Richard Biener wrote: > Are we using the wrong check or is escaping 'this' > for these kind of classes invoking undefined behavior? Wow, this got a lot of traffic quickly! Sounds like you (Richard, Andrew) = are on top of the issue here, where a constructor is involved; but once you sta= rt talking about heuristics and checks, I think it would be productive for you= two to make sure you're both on the same page with *this* example: // https://godbolt.org/z/Ea43Y65z4 struct Widget { int i =3D 1; int a[4]; }; Widget *global =3D nullptr; Widget make2() { Widget w; global =3D &w; return w; } void g() { global->i =3D 42; } int main() { Widget w =3D make2(); int i =3D w.i; g(); return (i =3D=3D w.i); // Does this need to be reloaded and // compared? or is it obviously true?=20=20 } In this case, Widget has no constructors, and I think it would be perfectly defensible for the compiler to say that "global =3D &w" is not a valid way = to escape the address of that prvalue result (even though copy elision will ma= ke the w in make() and the w in main() the same object). But do both of *you* = have the same answer to that paradox? If you don't, then you might also not agree about what the appropriate heuristic should be in the original case and mig= ht end up talking past each other.=