From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 02D2A3858C5E; Tue, 23 May 2023 17:53:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 02D2A3858C5E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1684864412; bh=ipHHJ1RSBBzuhvARlIeh/opxmXIyaJronqsFATWrOrM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Q2586qRuLtJJGZakELXsxXllN15OT2MiuSHV1xdK+wrMQ1L/BmG4GQeGb0mAlAkwt 9HKkpT1vbqq4RuvsMxmVx3XKkMGcemRLL8opING+fWQRCioiq9BmuEQ8D4yqLNIPPf L3TXqMOeCldd3BdEWwqtcJ1b/AQNlbAoOM9H2mWE= 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:53:31 +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 #10 from Andrew Pinski --- (In reply to Andrew Pinski from comment #9) > (In reply to Andrew Pinski from comment #8) > > (In reply to Arthur O'Dwyer from comment #7) > But does w go out of the scope at the end of make2? Similar question to m= ake > in the original testcase, does the temp go out of scope? For both of these testcases GCC currently warns even: : In function 'Widget make2()': :6:35: warning: storing the address of local variable ' w' in 'global' [-Wdangling-pointer=3D] 6 | Widget make2() { Widget w; global =3D &w; return w; } | ~~~~~~~^~~~ :6:1: note: ' w' declared here 6 | Widget make2() { Widget w; global =3D &w; return w; } | ^~~~~~ :5:9: note: 'global' declared here 5 | Widget *global =3D nullptr; | ^~~~~~ So Maybe this is undefined code after all.=