Skip to content

Commit e27c8c8

Browse files
committed
[+0-normal-args] When building the bodies of thunks, be sure to convert from +0 to +1.
Caught by the ownership verifier on the file test/SILGen/objc_currying.swift when compiling with +0 enabled. rdar://34222540
1 parent e5f9b1f commit e27c8c8

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

lib/SILGen/SILGenBridging.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -801,19 +801,31 @@ static void buildBlockToFuncThunkBody(SILGenFunction &SGF,
801801
assert(formalBlockParams.size() == blockTy->getNumParameters());
802802
assert(formalFuncParams.size() == funcTy->getNumParameters());
803803

804+
// Create the arguments for the call.
804805
for (unsigned i : indices(funcTy->getParameters())) {
805806
auto &param = funcTy->getParameters()[i];
806807
CanType formalBlockParamTy = formalBlockParams[i];
807808
CanType formalFuncParamTy = formalFuncParams[i];
808809

809810
auto paramTy = fnConv.getSILType(param);
810811
SILValue v = entry->createFunctionArgument(paramTy);
812+
813+
// First get the managed parameter for this function.
811814
auto mv = emitManagedParameter(SGF, loc, param, v);
812815

813816
SILType loweredBlockArgTy = blockTy->getParameters()[i].getSILStorageType();
814-
args.push_back(SGF.emitNativeToBridgedValue(loc, mv, formalFuncParamTy,
815-
formalBlockParamTy,
816-
loweredBlockArgTy));
817+
818+
// Then bridge the native value to its bridged variant.
819+
mv = SGF.emitNativeToBridgedValue(loc, mv, formalFuncParamTy,
820+
formalBlockParamTy, loweredBlockArgTy);
821+
822+
// Finally change ownership if we need to. We do not need to care about the
823+
// case of a +1 parameter being passed to a +0 function since +1 parameters
824+
// can be "instantaneously" borrowed at the call site.
825+
if (blockTy->getParameters()[i].isConsumed()) {
826+
mv = mv.ensurePlusOne(SGF, loc);
827+
}
828+
args.push_back(mv);
817829
}
818830

819831
// Add the block argument.

0 commit comments

Comments
 (0)