Skip to content

Commit 446dfbf

Browse files
authored
Merge pull request #69741 from DougGregor/typed-throws-minor-fixes
Typed throws minor fixes
2 parents 405ffed + bcf02f7 commit 446dfbf

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

Diff for: include/swift/SIL/SILFunction.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -1455,7 +1455,8 @@ class SILFunction
14551455
ArrayRef<SILArgument *> getArgumentsWithoutIndirectResults() const {
14561456
assert(!empty() && "Cannot get arguments of a function without a body");
14571457
return begin()->getArguments().slice(
1458-
getConventions().getNumIndirectSILResults());
1458+
getConventions().getNumIndirectSILResults() +
1459+
getConventions().getNumIndirectSILErrorResults());
14591460
}
14601461

14611462
const SILArgument *getSelfArgument() const {

Diff for: include/swift/SIL/SILInstruction.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -2902,7 +2902,9 @@ class ApplyInstBase<Impl, Base, true>
29022902
return getSubstCalleeConv().hasIndirectSILResults();
29032903
}
29042904
unsigned getNumIndirectResults() const {
2905-
return getSubstCalleeConv().getNumIndirectSILResults();
2905+
auto fnConv = getSubstCalleeConv();
2906+
return fnConv.getNumIndirectSILResults() +
2907+
fnConv.getNumIndirectSILErrorResults();
29062908
}
29072909

29082910
bool hasSelfArgument() const {

Diff for: lib/IRGen/IRGenDebugInfo.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -2480,6 +2480,7 @@ IRGenDebugInfoImpl::emitFunction(const SILDebugScope *DS, llvm::Function *Fn,
24802480
llvm::DITypeArray Error = nullptr;
24812481
if (FnTy && (Opts.DebugInfoLevel > IRGenDebugInfoLevel::LineTables))
24822482
if (auto ErrorInfo = FnTy->getOptionalErrorResult()) {
2483+
GenericContextScope scope(IGM, FnTy->getInvocationGenericSignature());
24832484
SILType SILTy = IGM.silConv.getSILType(
24842485
*ErrorInfo, FnTy, IGM.getMaximalTypeExpansionContext());
24852486
auto DTI = DebugTypeInfo::getFromTypeInfo(

Diff for: lib/SILOptimizer/Utils/SILInliner.cpp

+23
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)