From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id C77F33858D33; Tue, 20 Feb 2024 12:15:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C77F33858D33 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1708431314; bh=iTk6Hw4eIQ1e4tr7LAVDjBBvjUdR4tM3TTrLWErdmbg=; h=From:To:Subject:Date:In-Reply-To:References:From; b=yk3pdMQmWmKW0tRG5j6oL5mvMnK9wDa+5W/qeqr5qrnb+P1lFUUxlf9ZhSvB2Vmzh pycAt4U86pfd4rHfCs1MTrFTz4iXm4e///sGdH4ie1IlM7Sc/Eeg9aLaUIDsZDRZ3n Q9RWuIV5rGz9HDvlsyGSNb0rVa35xy5cqtQ3hC3k= From: "redi 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, 20 Feb 2024 12:15:13 +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: redi at gcc dot gnu.org X-Bugzilla-Status: NEW 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=3D109945 --- Comment #26 from Jonathan Wakely --- (In reply to Jonathan Wakely from comment #25) > However, [class.temporary] p3 explicitly allows the compiler to create a > temporary object when returning a class with a trivial copy constructor a= nd > trivial (or deleted) destructor. This is permitted precisely to allow what > the x86_64 ABI requires: the return value is passed in registers. Complet= ely > eliding the creation and copy of a temporary would have required an ABI > break. N.B. this permission to create an intermediate temporary only depends on the class type and whether it has a trivial copy constructor etc. *not* on the actual platform ABI and whether it _actually_ gets passed in registers or n= ot. So GCC is always allowed to make a temporary copy even on i686 where the ob= ject is really passed in memory via invisible reference, because the class has a trivial copy ctor. The fact that it doesn't actually make that copy on i686 doesn't make the program valid on i686 IMHO. Conceptually, there's a temporary which is copi= ed then goes out of scope, and the 'global' pointer becomes invalid and cannot= be dereferenced. The fact that the actual copy isn't present any more in the codegen (and the pointer happens to point to w itself which now exists at t= he same address as the temporary previously existed) doesn't make the program valid.=