diff --git a/include/swift/SIL/SILFunction.h b/include/swift/SIL/SILFunction.h index 7df71c6cd2094..5b0499ab0a005 100644 --- a/include/swift/SIL/SILFunction.h +++ b/include/swift/SIL/SILFunction.h @@ -1455,7 +1455,8 @@ class SILFunction ArrayRef getArgumentsWithoutIndirectResults() const { assert(!empty() && "Cannot get arguments of a function without a body"); return begin()->getArguments().slice( - getConventions().getNumIndirectSILResults()); + getConventions().getNumIndirectSILResults() + + getConventions().getNumIndirectSILErrorResults()); } const SILArgument *getSelfArgument() const { diff --git a/include/swift/SIL/SILInstruction.h b/include/swift/SIL/SILInstruction.h index 80c55ca9ce79a..0d2b82b1305e4 100644 --- a/include/swift/SIL/SILInstruction.h +++ b/include/swift/SIL/SILInstruction.h @@ -2902,7 +2902,9 @@ class ApplyInstBase return getSubstCalleeConv().hasIndirectSILResults(); } unsigned getNumIndirectResults() const { - return getSubstCalleeConv().getNumIndirectSILResults(); + auto fnConv = getSubstCalleeConv(); + return fnConv.getNumIndirectSILResults() + + fnConv.getNumIndirectSILErrorResults(); } bool hasSelfArgument() const { diff --git a/lib/IRGen/IRGenDebugInfo.cpp b/lib/IRGen/IRGenDebugInfo.cpp index 0cb0d9daef2c4..2415089cfcdea 100644 --- a/lib/IRGen/IRGenDebugInfo.cpp +++ b/lib/IRGen/IRGenDebugInfo.cpp @@ -2476,6 +2476,7 @@ IRGenDebugInfoImpl::emitFunction(const SILDebugScope *DS, llvm::Function *Fn, llvm::DITypeArray Error = nullptr; if (FnTy && (Opts.DebugInfoLevel > IRGenDebugInfoLevel::LineTables)) if (auto ErrorInfo = FnTy->getOptionalErrorResult()) { + GenericContextScope scope(IGM, FnTy->getInvocationGenericSignature()); SILType SILTy = IGM.silConv.getSILType( *ErrorInfo, FnTy, IGM.getMaximalTypeExpansionContext()); auto DTI = DebugTypeInfo::getFromTypeInfo( diff --git a/lib/SILOptimizer/Utils/SILInliner.cpp b/lib/SILOptimizer/Utils/SILInliner.cpp index 16f944428f2c0..560604739e1ea 100644 --- a/lib/SILOptimizer/Utils/SILInliner.cpp +++ b/lib/SILOptimizer/Utils/SILInliner.cpp @@ -626,6 +626,29 @@ void SILInlineCloner::visitTerminator(SILBasicBlock *BB) { return; } } + + // Modify throw_addr terminators to branch to the error-return BB, rather than + // trying to clone the ThrowAddrInst. + if (auto *TAI = dyn_cast(Terminator)) { + SILLocation Loc = getOpLocation(TAI->getLoc()); + switch (Apply.getKind()) { + case FullApplySiteKind::ApplyInst: + assert(cast(Apply)->isNonThrowing() + && "apply of a function with error result must be non-throwing"); + getBuilder().createUnreachable(Loc); + return; + case FullApplySiteKind::BeginApplyInst: + assert(cast(Apply)->isNonThrowing() + && "apply of a function with error result must be non-throwing"); + getBuilder().createUnreachable(Loc); + return; + case FullApplySiteKind::TryApplyInst: + auto tryAI = cast(Apply); + getBuilder().createBranch(Loc, tryAI->getErrorBB()); + return; + } + } + // Otherwise use normal visitor, which clones the existing instruction // but remaps basic blocks and values. visit(Terminator);