@@ -801,19 +801,31 @@ static void buildBlockToFuncThunkBody(SILGenFunction &SGF,
801
801
assert (formalBlockParams.size () == blockTy->getNumParameters ());
802
802
assert (formalFuncParams.size () == funcTy->getNumParameters ());
803
803
804
+ // Create the arguments for the call.
804
805
for (unsigned i : indices (funcTy->getParameters ())) {
805
806
auto ¶m = funcTy->getParameters ()[i];
806
807
CanType formalBlockParamTy = formalBlockParams[i];
807
808
CanType formalFuncParamTy = formalFuncParams[i];
808
809
809
810
auto paramTy = fnConv.getSILType (param);
810
811
SILValue v = entry->createFunctionArgument (paramTy);
812
+
813
+ // First get the managed parameter for this function.
811
814
auto mv = emitManagedParameter (SGF, loc, param, v);
812
815
813
816
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);
817
829
}
818
830
819
831
// Add the block argument.
0 commit comments