1515#include " ExecutorBreadcrumb.h"
1616#include " Initialization.h"
1717#include " LValue.h"
18+ #include " ManagedValue.h"
1819#include " RValue.h"
1920#include " SILGenFunction.h"
2021#include " SILGenFunctionBuilder.h"
2930#include " swift/Basic/Generators.h"
3031#include " swift/SIL/SILArgument.h"
3132#include " swift/SIL/SILInstruction.h"
33+ #include " swift/SIL/SILLocation.h"
3234#include " swift/SIL/SILUndef.h"
35+ #include " swift/SIL/SILValue.h"
3336#include " swift/SIL/TypeLowering.h"
3437#include < map>
3538
@@ -82,13 +85,14 @@ class LoweredParamsInContextGenerator {
8285
8386} // end anonymous namespace
8487
85- static ManagedValue emitManagedParameter (SILGenFunction &SGF,
86- SILValue value, bool isOwned ) {
88+ static ManagedValue emitManagedParameter (SILGenFunction &SGF, SILValue value,
89+ bool isOwned, SILLocation loc ) {
8790 if (isOwned) {
8891 return SGF.emitManagedRValueWithCleanup (value);
89- } else {
90- return ManagedValue::forBorrowedRValue (value);
9192 }
93+ if (value->getOwnershipKind () == OwnershipKind::Unowned)
94+ return ManagedValue::forUnownedObjectValue (value).ensurePlusOne (SGF, loc);
95+ return ManagedValue::forBorrowedRValue (value);
9296}
9397
9498static SILValue emitConstructorMetatypeArg (SILGenFunction &SGF,
@@ -216,7 +220,8 @@ static RValue emitImplicitValueConstructorArg(SILGenFunction &SGF,
216220 [&](Initialization *eltInit) {
217221 auto eltAddr =
218222 SGF.B .createPackElementGet (loc, packIndex, arg, eltTy);
219- ManagedValue eltMV = emitManagedParameter (SGF, eltAddr, argIsConsumed);
223+ ManagedValue eltMV =
224+ emitManagedParameter (SGF, eltAddr, argIsConsumed, loc);
220225 eltMV = SGF.B .createLoadIfLoadable (loc, eltMV);
221226 eltInit->copyOrInitValueInto (SGF, loc, eltMV, argIsConsumed);
222227 eltInit->finishInitialization (SGF);
@@ -226,7 +231,7 @@ static RValue emitImplicitValueConstructorArg(SILGenFunction &SGF,
226231 return RValue::forInContext ();
227232 }
228233
229- ManagedValue mvArg = emitManagedParameter (SGF, arg, argIsConsumed);
234+ ManagedValue mvArg = emitManagedParameter (SGF, arg, argIsConsumed, loc );
230235
231236 // This can happen if the value is resilient in the calling convention
232237 // but not resilient locally.
0 commit comments