From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 5327838708B5; Tue, 9 Jun 2020 18:35:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5327838708B5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1591727725; bh=+OWoEQXzmhNgK/CeyOE69iSL7fLl4IRjHlEHcF5uU8g=; h=From:To:Subject:Date:From; b=r/DldNk+t96AjRaHCA7dpPQrvIVMr+gREpqcWDIe7wyBQE6z4bnYTFceiSEtEKD1D Iom5Zu0JEfS6FAo8fXr/7GBZ4lLZzJ4lDvdiANSr0tTab9uKAbTRegcaQYnw5i56gd rrbGFN96gDCMshIAO40vIllfZUubBDtu4C7usgig= From: "lewissbaker.opensource at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/95615] New: [coroutines] Coroutine frame and promise is leaked if exception thrown from promise.initial_suspend() Date: Tue, 09 Jun 2020 18:35:25 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 10.1.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: lewissbaker.opensource at gmail 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: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 09 Jun 2020 18:35:25 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D95615 Bug ID: 95615 Summary: [coroutines] Coroutine frame and promise is leaked if exception thrown from promise.initial_suspend() Product: gcc Version: 10.1.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: lewissbaker.opensource at gmail dot com Target Milestone: --- If an exception is thrown from any of the following: - promise_type constructor - promise.get_return_object() - promise.initial_suspend() - initSuspendAwaitable.await_ready() - initSuspendAwaitable.await_suspend() Then I believe the compiler is required to automatically destroy the promise (if constructor completed successfully), destroy the return return-object (if get_return_object() completed successfully) and free the coroutine frame before letting the exception propagate to the caller. However, it seems that this cleanup logic is not currently begin called by GCC in these situations. For example, see https://godbolt.org/z/kQWjpF which shows the behaviour when an exception is thrown from promise.initial_suspend()'s await_suspend() method (other variants are commented out in the code). The wording described in [dcl.fct.def.coroutine] p5 in conjunction with p11 seems to indicate that the promise object should be destroyed as the exception propagates out of the coroutine.=