Skip to content

Commit 1d303ca

Browse files
committed
[Coroutines] fixed a bug when coro.end had an associated bundle, and a new cleanupret instruction was added, make it unwind to the same edge of the genuine cleanupret
1 parent 6ccbdcd commit 1d303ca

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

llvm/lib/Transforms/Coroutines/CoroSplit.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,16 @@ static void replaceUnwindCoroEnd(AnyCoroEndInst *End, const coro::Shape &Shape,
376376
// If coro.end has an associated bundle, add cleanupret instruction.
377377
if (auto Bundle = End->getOperandBundle(LLVMContext::OB_funclet)) {
378378
auto *FromPad = cast<CleanupPadInst>(Bundle->Inputs[0]);
379-
auto *CleanupRet = Builder.CreateCleanupRet(FromPad, nullptr);
379+
380+
// If the terminator is an invoke,
381+
// set the cleanupret unwind destination the same as the other edges, to
382+
// avoid validation errors
383+
BasicBlock *UBB = nullptr;
384+
if (auto II = dyn_cast<InvokeInst>(FromPad->getParent()->getTerminator())) {
385+
UBB = II->getUnwindDest();
386+
}
387+
388+
auto *CleanupRet = Builder.CreateCleanupRet(FromPad, UBB);
380389
End->getParent()->splitBasicBlock(End);
381390
CleanupRet->getParent()->getTerminator()->eraseFromParent();
382391
}

0 commit comments

Comments
 (0)