[PATCH] D115219: [C++20] [Coroutines] Mark coroutine done if unhandled_exception throws

Chuanqi Xu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 7 18:52:26 PST 2021


ChuanqiXu added a comment.

In D115219#3177213 <https://reviews.llvm.org/D115219#3177213>, @rjmccall wrote:

> Okay.  Well, I'm glad it works.  I guess I find it a little strange that `coro.end` doesn't already mark the coroutine done.  I guess the normal C++ lowering always generates a final suspension before reaching a non-unwind `coro.end`?

Yes, there is always a final suspend before coro.end in normal path. So that the coroutine would be marked done all the time except `unhandled_exception` throws.

> There are a lot of semantic differences between throwing out of a C++ coroutine and returning out of it that I always find surprising.

Yes, I guess this is the reason why the coroutine should be marked done if  `unhandled_exception` throws.

> Something ultimately invalidates the coroutine handle by deallocating the frame, right?

Yes, the coroutine frame is invalided by deallocating. Users (coroutine library writers) need to deallocate it by hand usually (by call `coroutine_handle<>::destroy()`). The coroutine would get destroyed automatically if the coroutine completes and not suspended at the final suspend point.

> When does that happen when throwing out of a coroutine?

After throwing out of a coroutine, the coroutine frame is still valid. And the owner is responsible to destroy it.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D115219/new/

https://reviews.llvm.org/D115219



More information about the cfe-commits mailing list