Insert default return_void at the end of coroutine body
authorBin Cheng <bin.cheng@linux.alibaba.com>
Mon, 9 Mar 2020 10:54:57 +0000 (18:54 +0800)
committerBin Cheng <bin.cheng@linux.alibaba.com>
Mon, 9 Mar 2020 10:54:57 +0000 (18:54 +0800)
commit016d0f9e43c1d2bd8227751b5b20a309c94edc90
tree865c048244c3f8f01427e8bd3afc581227a75513
parentcb2c60206f4f2218f84ccde21663b00de068d8c7
Insert default return_void at the end of coroutine body

Exception in coroutine is not correctly handled because the default
return_void call is now inserted before the finish suspend point,
rather than at the end of the original coroutine body.  This patch
fixes the issue by expanding code as following:
  co_await promise.initial_suspend();
  try {
    // The original coroutine body

    promise.return_void(); // The default return_void call.
  } catch (...) {
    promise.unhandled_exception();
  }
  final_suspend:
  // ...

gcc/cp/
    * coroutines.cc (build_actor_fn): Factor out code inserting the
    default return_void call to...
    (morph_fn_to_coro): ...here, also hoist local var declarations.

gcc/testsuite/
    * g++.dg/coroutines/torture/co-ret-15-default-return_void.C: New.
gcc/cp/ChangeLog
gcc/cp/coroutines.cc
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/coroutines/torture/co-ret-15-default-return_void.C [new file with mode: 0644]