]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++, coroutines: Fix handling of bool await_suspend() [PR115905].
authorIain Sandoe <iain@sandoe.co.uk>
Fri, 6 Sep 2024 19:59:43 +0000 (20:59 +0100)
committerIain Sandoe <iain@sandoe.co.uk>
Sun, 15 Sep 2024 06:39:55 +0000 (10:39 +0400)
commit368ba7aed46d57d093c0180baae4dc0e0ba468b6
tree08e5444affefb5e10afa367c114ef1eca3864125
parent6e4244e8ceac939fe8a24470b4ff31c82e8bff21
c++, coroutines: Fix handling of bool await_suspend() [PR115905].

As noted in the PR the action of the existing implementation was to
treat a false value from await_suspend () as equivalent to "do not
suspend".  Actually it needs to be the equivalent of "resume" - and
we need to restart the dispatcher - since the await_suspend() body
could have already resumed the coroutine.
See also https://github.com/cplusplus/CWG/issues/601 (NAD) for more
discussion.

Since we need to amend the await expansion and the actor build, take
the opportunity to clean up and modernise the code there.  Note that
we need to make the jump back to the dispatcher without any scope
exit cleanups (so we have to use the .CO_SUSPN IFN to do this).

PR c++/115905

gcc/cp/ChangeLog:

* coroutines.cc (struct coro_aw_data): Add a member for the
restart dispatch label.
(expand_one_await_expression): Rework to modernise and to
handle the boolean await_suspend() case.
(build_actor_fn): Rework the dispatcher and allow for a jump
back to the dispatcher.

gcc/testsuite/ChangeLog:

* g++.dg/coroutines/torture/pr115905.C: New test.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
gcc/cp/coroutines.cc
gcc/testsuite/g++.dg/coroutines/torture/pr115905.C [new file with mode: 0644]