[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 00:58:38 PST 2021
ChuanqiXu updated this revision to Diff 392302.
ChuanqiXu edited the summary of this revision.
ChuanqiXu added a comment.
Use `llvm.coro.end(frame, /*InUnwindPath=*/true)` instead of new coroutine intrinsics.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D115219/new/
https://reviews.llvm.org/D115219
Files:
llvm/lib/Transforms/Coroutines/CoroSplit.cpp
llvm/test/Transforms/Coroutines/coro-split-eh-00.ll
llvm/test/Transforms/Coroutines/coro-split-eh-01.ll
Index: llvm/test/Transforms/Coroutines/coro-split-eh-01.ll
===================================================================
--- llvm/test/Transforms/Coroutines/coro-split-eh-01.ll
+++ llvm/test/Transforms/Coroutines/coro-split-eh-01.ll
@@ -61,6 +61,9 @@
; CHECK: lpad:
; CHECK-NEXT: %tok = cleanuppad within none []
; CHECK-NEXT: call void @print(i32 2)
+; Checks that the coroutine would be marked as done if it exits in unwinding path.
+; CHECK-NEXT: %[[RESUME_ADDR:.+]] = getelementptr inbounds %[[FRAME_TY:.+]], %[[FRAME_TY]]* %FramePtr, i32 0, i32 0
+; CHECK-NEXT: store void (%[[FRAME_TY]]*)* null, void (%[[FRAME_TY]]*)** %[[RESUME_ADDR]], align 8
; CHECK-NEXT: cleanupret from %tok unwind to caller
declare i8* @llvm.coro.free(token, i8*)
Index: llvm/test/Transforms/Coroutines/coro-split-eh-00.ll
===================================================================
--- llvm/test/Transforms/Coroutines/coro-split-eh-00.ll
+++ llvm/test/Transforms/Coroutines/coro-split-eh-00.ll
@@ -67,6 +67,9 @@
; CHECK-NEXT: %lpval = landingpad { i8*, i32 }
; CHECK-NEXT: cleanup
; CHECK-NEXT: call void @print(i32 2)
+; Checks that the coroutine would be marked as done if it exits in unwinding path.
+; CHECK-NEXT: %[[RESUME_ADDR:.+]] = getelementptr inbounds %[[FRAME_TY:.+]], %[[FRAME_TY]]* %FramePtr, i32 0, i32 0
+; CHECK-NEXT: store void (%[[FRAME_TY]]*)* null, void (%[[FRAME_TY]]*)** %[[RESUME_ADDR]], align 8
; CHECK-NEXT: resume { i8*, i32 } %lpval
declare i8* @llvm.coro.free(token, i8*)
Index: llvm/lib/Transforms/Coroutines/CoroSplit.cpp
===================================================================
--- llvm/lib/Transforms/Coroutines/CoroSplit.cpp
+++ llvm/lib/Transforms/Coroutines/CoroSplit.cpp
@@ -288,10 +288,24 @@
switch (Shape.ABI) {
// In switch-lowering, this does nothing in the main function.
- case coro::ABI::Switch:
+ case coro::ABI::Switch: {
+ // In C++'s specificatin, the corotine should be marked as done
+ // if the coroutine leaves in unwinding path.
+ //
+ // FIXME: We should refactor this once there is other language
+ // which uses Switch-Resumed style other than C++.
+ //
+ // Done state is represented by storing zero in ResumeFnAddr.
+ auto *GepIndex = Builder.CreateStructGEP(
+ Shape.FrameTy, FramePtr, coro::Shape::SwitchFieldIndex::Resume,
+ "ResumeFn.addr");
+ auto *NullPtr = ConstantPointerNull::get(cast<PointerType>(
+ Shape.FrameTy->getTypeAtIndex(coro::Shape::SwitchFieldIndex::Resume)));
+ Builder.CreateStore(NullPtr, GepIndex);
if (!InResume)
return;
break;
+ }
// In async lowering this does nothing.
case coro::ABI::Async:
break;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D115219.392302.patch
Type: text/x-patch
Size: 2744 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211207/cb480b34/attachment.bin>
More information about the cfe-commits
mailing list