coroutines : Handle exceptions throw before the first await_resume() [PR95615].
authorIain Sandoe <iain@sandoe.co.uk>
Mon, 15 Feb 2021 15:09:27 +0000 (15:09 +0000)
committerIain Sandoe <iain@sandoe.co.uk>
Fri, 5 Mar 2021 16:55:16 +0000 (16:55 +0000)
commitfe55086547c9360b530e040a6673dae10ac77847
tree9cd6ec75144d83d20311bd8574798ab8986e4ea4
parent9105757a59b890194ebf5b4fcbacd58db34ef332
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.  Originally, 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 portion 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 parameter
copies, or the promise object or the return object any of which might have 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 exception,
likewise the frame promise and the return object.  On exception, run the
DTORs for these, destroy the frame and then rethrow the exception.

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.
gcc/cp/coroutines.cc
gcc/testsuite/g++.dg/coroutines/torture/pr95615-01.C [new file with mode: 0644]
gcc/testsuite/g++.dg/coroutines/torture/pr95615-02.C [new file with mode: 0644]
gcc/testsuite/g++.dg/coroutines/torture/pr95615-03.C [new file with mode: 0644]
gcc/testsuite/g++.dg/coroutines/torture/pr95615-04.C [new file with mode: 0644]
gcc/testsuite/g++.dg/coroutines/torture/pr95615-05.C [new file with mode: 0644]
gcc/testsuite/g++.dg/coroutines/torture/pr95615.inc [new file with mode: 0644]
This page took 0.121564 seconds and 6 git commands to generate.