@@ -1823,8 +1823,8 @@ SILGenFunction::emitApplyOfSetterToBase(SILLocation loc, SILDeclRef setter,
18231823 SmallVector<ManagedValue, 4 > captures;
18241824 emitCaptures (loc, setter, CaptureEmission::AssignByWrapper, captures);
18251825
1826- for ( auto capture : captures)
1827- capturedArgs. push_back ( capture. forward (* this ) );
1826+ llvm::transform (captures, std::back_inserter (capturedArgs),
1827+ []( auto & capture) { return capture. getValue (); } );
18281828 } else {
18291829 assert (base);
18301830
@@ -1842,16 +1842,20 @@ SILGenFunction::emitApplyOfSetterToBase(SILLocation loc, SILDeclRef setter,
18421842 // nonmutating setter, for example.
18431843 capturedBase = B.createTrivialLoadOr (loc, base.getValue (),
18441844 LoadOwnershipQualifier::Copy);
1845+ // On-stack partial apply doesn't take ownership of the base, so
1846+ // we have to destroy it manually.
1847+ enterDestroyCleanup (capturedBase);
18451848 } else {
1846- capturedBase = base.copy (*this , loc).forward (* this );
1849+ capturedBase = base.borrow (*this , loc).getValue ( );
18471850 }
18481851
18491852 capturedArgs.push_back (capturedBase);
18501853 }
18511854
18521855 PartialApplyInst *setterPAI =
18531856 B.createPartialApply (loc, setterFRef, substitutions, capturedArgs,
1854- ParameterConvention::Direct_Guaranteed);
1857+ ParameterConvention::Direct_Guaranteed,
1858+ PartialApplyInst::OnStackKind::OnStack);
18551859 return emitManagedRValueWithCleanup (setterPAI).getValue ();
18561860}
18571861
0 commit comments