File tree Expand file tree Collapse file tree 3 files changed +24
-3
lines changed Expand file tree Collapse file tree 3 files changed +24
-3
lines changed Original file line number Diff line number Diff line change @@ -1362,7 +1362,11 @@ static bool knowHowToEmitReferenceCountInsts(ApplyInst *Call) {
1362
1362
if (Call->getNumArguments () != 1 )
1363
1363
return false ;
1364
1364
1365
- FunctionRefInst *FRI = cast<FunctionRefInst>(Call->getCallee ());
1365
+ // FIXME: We could handle dynamic_function_ref instructions here because the
1366
+ // code only looks at the function type.
1367
+ FunctionRefInst *FRI = dyn_cast<FunctionRefInst>(Call->getCallee ());
1368
+ if (!FRI)
1369
+ return false ;
1366
1370
SILFunction *F = FRI->getReferencedFunction ();
1367
1371
auto FnTy = F->getLoweredFunctionType ();
1368
1372
Original file line number Diff line number Diff line change @@ -271,7 +271,7 @@ CastOptimizer::optimizeBridgedObjCToSwiftCast(SILDynamicCastInst dynamicCast) {
271
271
// Now emit the a cast from the casted ObjC object into a target type.
272
272
// This is done by means of calling _forceBridgeFromObjectiveC or
273
273
// _conditionallyBridgeFromObjectiveC_bridgeable from the Target type.
274
- auto *funcRef = Builder.createFunctionRef (Loc, bridgingFunc);
274
+ auto *funcRef = Builder.createFunctionRefFor (Loc, bridgingFunc);
275
275
SubstitutionMap subMap = lookupBridgeToObjCProtocolSubs (mod, target);
276
276
277
277
auto MetaTy = MetatypeType::get (target, MetatypeRepresentation::Thick);
@@ -588,7 +588,7 @@ CastOptimizer::optimizeBridgedSwiftToObjCCast(SILDynamicCastInst dynamicCast) {
588
588
}
589
589
590
590
SILBuilderWithScope Builder (Inst, builderContext);
591
- auto FnRef = Builder.createFunctionRef (Loc, bridgedFunc);
591
+ auto FnRef = Builder.createFunctionRefFor (Loc, bridgedFunc);
592
592
auto ParamTypes = SubstFnTy.castTo <SILFunctionType>()->getParameters ();
593
593
if (Src->getType ().isAddress () && !substConv.isSILIndirect (ParamTypes[0 ])) {
594
594
// Create load
Original file line number Diff line number Diff line change @@ -64,6 +64,23 @@ bb0(%0 : $AnNSArray):
64
64
return %4 : $AnNSArray
65
65
}
66
66
67
+ sil [_semantics "convertFromObjectiveC"] [dynamically_replacable] @bridgeFromObjectiveC2 :
68
+ $@convention(thin) <τ_0_0> (@owned AnNSArray) -> @owned AnArray<τ_0_0>
69
+
70
+ sil [_semantics "convertToObjectiveC"] [dynamically_replacable] @bridgeToObjectiveC2:
71
+ $@convention(method) <τ_0_0> (@owned AnArray<τ_0_0>) -> @owned AnNSArray
72
+
73
+ // This should not crash.
74
+ sil @bridge_from_to_owned_dynamic : $@convention(thin) (@owned AnNSArray) -> @owned AnNSArray {
75
+ bb0(%0 : $AnNSArray):
76
+ %1 = dynamic_function_ref @bridgeFromObjectiveC2 : $@convention(thin) <AnyObject> (@owned AnNSArray) -> @owned AnArray<AnyObject>
77
+ %2 = apply %1<AnyObject>(%0) : $@convention(thin) <AnyObject> (@owned AnNSArray) -> @owned AnArray<AnyObject>
78
+ retain_value %2 : $AnArray<AnyObject>
79
+ release_value %2 : $AnArray<AnyObject>
80
+ %3 = dynamic_function_ref @bridgeToObjectiveC2 : $@convention(method) <AnyObject> (@owned AnArray<AnyObject>) -> @owned AnNSArray
81
+ %4 = apply %3<AnyObject>(%2) : $@convention(method) <AnyObject> (@owned AnArray<AnyObject>) -> @owned AnNSArray
82
+ return %4 : $AnNSArray
83
+ }
67
84
// CHECK-LABEL: sil @bridge_to_from_owned
68
85
// CHECK-NOT: apply
69
86
// CHECK: retain_value
You can’t perform that action at this time.
0 commit comments