@@ -1672,23 +1672,29 @@ void StmtEmitter::visitFailStmt(FailStmt *S) {
16721672
16731673// / Return a basic block suitable to be the destination block of a
16741674// / try_apply instruction. The block is implicitly emitted and filled in.
1675+ // /
1676+ // / \param errorAddrOrType Either the address of the indirect error result where
1677+ // / the result will be stored, or the type of the expected Owned error value.
1678+ // /
1679+ // / \param suppressErrorPath Should the error path be emitted as unreachable?
16751680SILBasicBlock *
16761681SILGenFunction::getTryApplyErrorDest (SILLocation loc,
16771682 CanSILFunctionType fnTy,
16781683 ExecutorBreadcrumb prevExecutor,
1679- SILResultInfo errorResult,
1680- SILValue indirectErrorAddr,
1684+ TaggedUnion<SILValue, SILType> errorAddrOrType,
16811685 bool suppressErrorPath) {
16821686 // For now, don't try to re-use destination blocks for multiple
16831687 // failure sites.
16841688 SILBasicBlock *destBB = createBasicBlock (FunctionSection::Postmatter);
16851689
16861690 SILValue errorValue;
1687- if (errorResult. getConvention () == ResultConvention::Owned ) {
1688- errorValue = destBB->createPhiArgument (getSILType (errorResult, fnTy) ,
1689- OwnershipKind::Owned);
1691+ if (auto ownedErrorTy = errorAddrOrType. dyn_cast <SILType>() ) {
1692+ errorValue = destBB->createPhiArgument (*ownedErrorTy ,
1693+ OwnershipKind::Owned);
16901694 } else {
1691- errorValue = indirectErrorAddr;
1695+ auto errorAddr = errorAddrOrType.get <SILValue>();
1696+ assert (errorAddr->getType ().isAddress ());
1697+ errorValue = errorAddr;
16921698 }
16931699
16941700 assert (B.hasValidInsertionPoint () && B.insertingAtEndOfBlock ());
@@ -1761,9 +1767,6 @@ void SILGenFunction::emitThrow(SILLocation loc, ManagedValue exnMV,
17611767 } else {
17621768 // Call the _willThrowTyped entrypoint, which handles
17631769 // arbitrary error types.
1764- SILValue tmpBuffer;
1765- SILValue error;
1766-
17671770 FuncDecl *entrypoint = ctx.getWillThrowTyped ();
17681771 auto genericSig = entrypoint->getGenericSignature ();
17691772 SubstitutionMap subMap = SubstitutionMap::get (
@@ -1776,18 +1779,15 @@ void SILGenFunction::emitThrow(SILLocation loc, ManagedValue exnMV,
17761779 // Materialize the error so we can pass the address down to the
17771780 // swift_willThrowTyped.
17781781 exnMV = exnMV.materialize (*this , loc);
1779- error = exnMV.getValue ();
1780- exn = exnMV.forward (*this );
1781- } else {
1782- // Claim the exception value.
1783- exn = exnMV.forward (*this );
1784- error = exn;
17851782 }
17861783
17871784 emitApplyOfLibraryIntrinsic (
17881785 loc, entrypoint, subMap,
1789- { ManagedValue::forForwardedRValue (* this , error) },
1786+ { exnMV },
17901787 SGFContext ());
1788+
1789+ // Claim the exception value.
1790+ exn = exnMV.forward (*this );
17911791 }
17921792 } else {
17931793 // Claim the exception value.
@@ -1857,8 +1857,8 @@ void SILGenFunction::emitThrow(SILLocation loc, ManagedValue exnMV,
18571857 B.createDestroyAddr (loc, exn);
18581858 }
18591859
1860- // Branch to the cleanup destination .
1861- Cleanups.emitCleanupsForBranch (ThrowDest, loc, args , IsForUnwind);
1860+ // Emit clean-ups needed prior to entering throw block .
1861+ Cleanups.emitCleanupsBeforeBranch (ThrowDest, IsForUnwind);
18621862
18631863 if (indirectErrorAddr && !exn->getType ().isAddress ()) {
18641864 // Forward the error value into the return slot now. This has to happen
0 commit comments