From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id F32173840C27; Fri, 5 Mar 2021 16:59:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F32173840C27 From: "cvs-commit at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/95615] [coroutines] Coroutine frame and promise is leaked if exception thrown from promise.initial_suspend() Date: Fri, 05 Mar 2021 16:59:19 +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: 10.1.1 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: cvs-commit at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: iains at gcc dot gnu.org X-Bugzilla-Target-Milestone: 10.3 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 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: Fri, 05 Mar 2021 16:59:20 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D95615 --- Comment #5 from CVS Commits --- The master branch has been updated by Iain D Sandoe : https://gcc.gnu.org/g:fe55086547c9360b530e040a6673dae10ac77847 commit r11-7527-gfe55086547c9360b530e040a6673dae10ac77847 Author: Iain Sandoe Date: Mon Feb 15 15:09:27 2021 +0000 coroutines : Handle exceptions throw before the first await_resume() [PR95615]. The coroutine body is wrapped in a try-catch block which is responsible= for handling any exceptions thrown by the original function body. Original= ly, the initial suspend expression was outside this, but an amendement to the standard places the await_resume call inside and eveything else outside. This means that any exception thrown prior to the initial suspend expression await_resume() will propagate to the ramp function. However, some port= ion of the coroutine state will exist at that point (how much depends on where= the exception is thrown from). For example, we might have some frame param= eter copies, or the promise object or the return object any of which might h= ave a non-trivial DTOR. Also the frame itself needs to be deallocated. This patch fixes the handling of these cases. gcc/cp/ChangeLog: PR c++/95615 * coroutines.cc (struct param_info): Track parameter copies that need a DTOR. (coro_get_frame_dtor): New helper function factored from build_actor(). (build_actor_fn): Use coro_get_frame_dtor(). (morph_fn_to_coro): Track parameters that need DTORs on excepti= on, likewise the frame promise and the return object. On exception, run the DTORs for these, destroy the frame and then rethrow the excepti= on. gcc/testsuite/ChangeLog: PR c++/95615 * g++.dg/coroutines/torture/pr95615-01.C: New test. * g++.dg/coroutines/torture/pr95615-02.C: New test. * g++.dg/coroutines/torture/pr95615-03.C: New test. * g++.dg/coroutines/torture/pr95615-04.C: New test. * g++.dg/coroutines/torture/pr95615-05.C: New test.=