From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id A13643858D39; Wed, 29 Mar 2023 07:11:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A13643858D39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1680073867; bh=1HC/jq8vte6hwPbMW3oqUf84JfkqW2B5X/12N8+m+PU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=hDXf8nDhnuuCQG3ng5f0cVsQT3BITKVrTeZp719i3fk+UMbBPv1y1pKkabZxNUSjE 0ocdPa3+WQtjm4CrX/aEbCrjnXo1wGD8As5F1QHnA3jBbb3jYpMbiCAbsv4SqpuO3X vJYBe2vfCrTvX1gCIJSQU+kZn0d6zGwgpg7oBgwk= From: "StevenSun2021 at hotmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/109283] Destructor of co_yield conditional argument called twice Date: Wed, 29 Mar 2023 07:11:07 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 12.2.0 X-Bugzilla-Keywords: C++-coroutines, ice-on-valid-code, wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: StevenSun2021 at hotmail dot com 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: cc 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=3D109283 Steven Sun changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |StevenSun2021 at hotmail d= ot com --- Comment #1 from Steven Sun --- It is indeed a bug. I currently only investigated into the gcc-12, it gener= ates something for ``` struct S{ /**/ }; bool w; co_yield w ? S{"a"} : S{"b"}; ``` pseudo-code for the generated gimple: ``` char __res[sizeof(S)]; char __a[sizeof(S)]; char __b[sizeof(S)]; new (__a) S("a"); new (__b) S("b"); if (w) memcpy(__res, __a, sizeof(S)); else memcpy(__res, __b, sizeof(S)); /* ... */ __b->~S(); __a->~S(); __c->~S(); ``` So, clearly there is at least 3 bugs here: i. `__res` is never constructed. ii. only one of the `__a` and `__b` should be constructed, not both. iii. the assignment is not corrected (it uses `gimple_assign` for value cop= y).=20 If the ii is correctly implemented, iii will not happen. Though, the code will work fine on all trivial types. The correct code should be ``` char __res[sizeof(S)]; if (w) new (__res) S("a"); else new (__res) S("b"); /* ... */ __res->~S(); ```=