[llvm-dev] What's the difference between llvm `resume` instruction and `__cxa_rethrow`?
chuanqi.xcq via llvm-dev
llvm-dev at lists.llvm.org
Tue Nov 30 23:36:35 PST 2021
Hi,
Recently I am checking the implementation of c++20 coroutine in clang and I am wondering if it is possible to mark its status as complete.
(Now the status is partial althought it's been a while that the clang's coroutine is used in production).
Here is the simple introduction, in the standard: https://eel.is/c++draft/dcl.fct.def.coroutine#5, it says both initial_suspend().await_ready()
and initial_suspend().await_suspend() should be wrapped in `try` statement and if there is an exception happens, it would be rethown by
`throw;` statement. It may look like:
```C++
try {
auto init_suspend = promise.init_suspend();
if (!init_suspend.await_ready())
init_suspend.await_suspend();
} catch (...) {
throw;
}
```
And the implementation didn't wrap them in `try...catch` statement. The code generated by clang would look like:
```LLVM
invoke promise.init_suspend()
to label %cont unwind label %lpad
invoke init_suspend.await_ready()
to label %cont1 unwind label %lpad1
invoke init_suspend.await_suspend()
to label %cont2 unwind label %lpad2
...
%lpad:
...
br label %eh.resume
%lpad1:
...
br label %eh.resume
%lpad2:
...
br label %eh.resume
eh.resume:
....
resume
```
And I know that clang would generate `__cxa_rethrow` for `throw;`. I did some simple test locally, the behavior now looks
good for me. (I could catch the exception in the caller of the coroutine). But I think it would be better to consult with the experts.
I am wondering what's the difference and if it would be a block issue for conforming clang's implementation.
Thanks,
Chuanqi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20211201/152f7c41/attachment.html>
More information about the llvm-dev
mailing list