@@ -757,7 +757,8 @@ class BridgedArgument {
757
757
: BridgeFun(nullptr ), BridgeCall(nullptr ), OptionalResult(nullptr ),
758
758
ReleaseAfterBridge(nullptr ), ReleaseArgAfterCall(nullptr ), Idx(0 ) {}
759
759
760
- static BridgedArgument match (unsigned ArgIdx, SILValue Arg, ApplyInst *AI);
760
+ static BridgedArgument match (unsigned ArgIdx, SILValue Arg, ApplyInst *AI,
761
+ DeadEndBlocks *deBlocks);
761
762
762
763
operator bool () const { return BridgeFun != nullptr ; }
763
764
SILValue bridgedValue () { return BridgedValue; }
@@ -826,7 +827,7 @@ static SILInstruction *findReleaseOf(SILValue releasedValue,
826
827
}
827
828
828
829
BridgedArgument BridgedArgument::match (unsigned ArgIdx, SILValue Arg,
829
- ApplyInst *AI) {
830
+ ApplyInst *AI, DeadEndBlocks *deBlocks ) {
830
831
// Match
831
832
// %15 = function_ref @$SSS10FoundationE19_bridgeToObjectiveCSo8NSStringCyF
832
833
// %16 = apply %15(%14) : $@convention(method) (@guaranteed String) -> @owned NSString
@@ -879,6 +880,7 @@ BridgedArgument BridgedArgument::match(unsigned ArgIdx, SILValue Arg,
879
880
880
881
if (SILBasicBlock::iterator (BridgeCall) == BridgeCall->getParent ()->begin ())
881
882
return BridgedArgument ();
883
+
882
884
auto *FunRef =
883
885
dyn_cast<FunctionRefInst>(std::prev (SILBasicBlock::iterator (BridgeCall)));
884
886
if (!FunRef || !FunRef->hasOneUse () || BridgeCall->getCallee () != FunRef)
@@ -912,6 +914,12 @@ BridgedArgument BridgedArgument::match(unsigned ArgIdx, SILValue Arg,
912
914
BridgeFun->getName () != bridgeWitness.mangle ())
913
915
return BridgedArgument ();
914
916
917
+ if (hasOwnership && !BridgedValueRelease) {
918
+ SmallVector<Operand *> newUses{&AI->getOperandRef (ArgIdx)};
919
+ if (!areUsesWithinValueLifetime (BridgedValue, newUses, deBlocks)) {
920
+ return BridgedArgument ();
921
+ }
922
+ }
915
923
return BridgedArgument (ArgIdx, FunRef, BridgeCall, Enum, BridgedValueRelease,
916
924
ReleaseAfter);
917
925
}
@@ -1215,7 +1223,8 @@ bool ObjCMethodCall::matchInstSequence(SILBasicBlock::iterator I) {
1215
1223
if (Ty.isAnyObject ())
1216
1224
continue ;
1217
1225
1218
- auto BridgedArg = BridgedArgument::match (CurIdx, Param.get (), BridgedCall);
1226
+ auto BridgedArg =
1227
+ BridgedArgument::match (CurIdx, Param.get (), BridgedCall, deBlocks);
1219
1228
if (!BridgedArg)
1220
1229
continue ;
1221
1230
0 commit comments