From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 3FF423858C54; Tue, 23 May 2023 17:52:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3FF423858C54 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1684864322; bh=XKbgpzS8OWBU0t/1DhssKdvV1ZjhQxuBtcUtmNFowcw=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Wvin6uLXDsia6ZJxoPrnGRjBwX+KSxl5eeqKJ8bbKtQyKzWjCuEXvBlwEQ9bYISSa MsQLQlWnGpeUXQ+Oewm6asYtCKLGevEm6sMvQG4WOhMYdqwa9ocWHzUT0La/+O7eCd JUW45Eeuklvs1QMJk5yDgABFOOHT6nncUHE4N8Us= From: "pinskia at gcc dot gnu.org" 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:52:01 +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: pinskia at gcc dot gnu.org 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 #9 from Andrew Pinski --- (In reply to Andrew Pinski from comment #8) > (In reply to Arthur O'Dwyer from comment #7) > > // https://godbolt.org/z/Ea43Y65z4 > > struct Widget { > > int i =3D 1; > ... > > In this case, Widget has no constructors, >=20 > No, it has a constructor because of the NSDMI . NSDMI causes a non-trival > constexpr constructor to be created. Now this version does not: ``` struct Widget { int i; int a[4]; }; Widget *global =3D 0; Widget make2() { Widget w; w.i =3D 1; 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 } ``` But does w go out of the scope at the end of make2? Similar question to mak= e in the original testcase, does the temp go out of scope?=