Skip to content

Commit 3c5e9cb

Browse files
committed
[SIL] Clone throw_addr instructions by branching to the error basic block
This is the same way we handle `throw` instructions, but without the operand.
1 parent d031296 commit 3c5e9cb

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

lib/SILOptimizer/Utils/SILInliner.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,29 @@ void SILInlineCloner::visitTerminator(SILBasicBlock *BB) {
626626
return;
627627
}
628628
}
629+
630+
// Modify throw_addr terminators to branch to the error-return BB, rather than
631+
// trying to clone the ThrowAddrInst.
632+
if (auto *TAI = dyn_cast<ThrowAddrInst>(Terminator)) {
633+
SILLocation Loc = getOpLocation(TAI->getLoc());
634+
switch (Apply.getKind()) {
635+
case FullApplySiteKind::ApplyInst:
636+
assert(cast<ApplyInst>(Apply)->isNonThrowing()
637+
&& "apply of a function with error result must be non-throwing");
638+
getBuilder().createUnreachable(Loc);
639+
return;
640+
case FullApplySiteKind::BeginApplyInst:
641+
assert(cast<BeginApplyInst>(Apply)->isNonThrowing()
642+
&& "apply of a function with error result must be non-throwing");
643+
getBuilder().createUnreachable(Loc);
644+
return;
645+
case FullApplySiteKind::TryApplyInst:
646+
auto tryAI = cast<TryApplyInst>(Apply);
647+
getBuilder().createBranch(Loc, tryAI->getErrorBB());
648+
return;
649+
}
650+
}
651+
629652
// Otherwise use normal visitor, which clones the existing instruction
630653
// but remaps basic blocks and values.
631654
visit(Terminator);

0 commit comments

Comments
 (0)