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 @@ -1176,7 +1176,11 @@ static bool knowHowToEmitReferenceCountInsts(ApplyInst *Call) {
1176
1176
if (Call->getNumArguments () != 1 )
1177
1177
return false ;
1178
1178
1179
- FunctionRefInst *FRI = cast<FunctionRefInst>(Call->getCallee ());
1179
+ // FIXME: We could handle dynamic_function_ref instructions here because the
1180
+ // code only looks at the function type.
1181
+ FunctionRefInst *FRI = dyn_cast<FunctionRefInst>(Call->getCallee ());
1182
+ if (!FRI)
1183
+ return false ;
1180
1184
SILFunction *F = FRI->getReferencedFunction ();
1181
1185
auto FnTy = F->getLoweredFunctionType ();
1182
1186
Original file line number Diff line number Diff line change @@ -190,7 +190,7 @@ CastOptimizer::optimizeBridgedObjCToSwiftCast(SILDynamicCastInst dynamicCast) {
190
190
// Now emit the a cast from the casted ObjC object into a target type.
191
191
// This is done by means of calling _forceBridgeFromObjectiveC or
192
192
// _conditionallyBridgeFromObjectiveC_bridgeable from the Target type.
193
- auto *funcRef = Builder.createFunctionRef (Loc, bridgingFunc);
193
+ auto *funcRef = Builder.createFunctionRefFor (Loc, bridgingFunc);
194
194
SubstitutionMap subMap = lookupBridgeToObjCProtocolSubs (mod, target);
195
195
196
196
auto MetaTy = MetatypeType::get (target, MetatypeRepresentation::Thick);
@@ -430,7 +430,7 @@ CastOptimizer::optimizeBridgedSwiftToObjCCast(SILDynamicCastInst dynamicCast) {
430
430
}
431
431
432
432
SILBuilderWithScope Builder (Inst, BuilderContext);
433
- auto FnRef = Builder.createFunctionRef (Loc, bridgedFunc);
433
+ auto FnRef = Builder.createFunctionRefFor (Loc, bridgedFunc);
434
434
auto ParamTypes = SubstFnTy.castTo <SILFunctionType>()->getParameters ();
435
435
if (Src->getType ().isAddress () && !substConv.isSILIndirect (ParamTypes[0 ])) {
436
436
// 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