https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100897
N <gccbugzilla at maycontaincode dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |gccbugzilla@maycontaincode.
| |com
--- Comment #4 from N <gccbugzilla at maycontaincode dot com> ---
Just wanted to add, if any space is used in the coroutine frame to fix this,
make sure it's in the target coroutine frame, not the coroutine frame of the
coroutine that just suspended. Otherwise you'll end up with the same broken
behavior MSVC suffered from, where any attempt to destroy the just-suspended
coroutine (either in the same thread or a different thread) before returning
the continuation from await_suspend resulted in use-after-free. They only
recently fixed it, and I'm not sure what their solution was.
I am not convinced tail calls are truly necessary to implement symmetric
transfer though, another option is having two versions of .resume(): the
public-facing version that works as expected, and a private version that does
the actual resuming and just returns the next coroutine handle. The
public-facing version can just call that private one in a loop, overwriting the
coroutine handle on the stack, and breaking at a noop-coroutine. However, this
would be an ABI break if it's not already implemented this way. It's also less
efficient than the tail call version due to having to branch to know when to
exit the loop. Maybe that can be avoided with some magic in the noop coroutine
resume implementation though.