Skip to content

Commit b2e2135

Browse files
authored
Merge pull request #21712 from aschwaighofer/outliner_fix_open_existential_5.0
[5.0] Outliner: We don't support calls with opened existentials
2 parents 4f76d25 + 016a37f commit b2e2135

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

lib/SILOptimizer/Transforms/Outliner.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,8 @@ bool BridgedProperty::matchMethodCall(SILBasicBlock::iterator It) {
554554
if (!ObjCMethod || !ObjCMethod->hasOneUse() ||
555555
ObjCMethod->getOperand() != Instance ||
556556
ObjCMethod->getFunction()->getLoweredFunctionType()->isPolymorphic() ||
557-
ObjCMethod->getType().castTo<SILFunctionType>()->isPolymorphic())
557+
ObjCMethod->getType().castTo<SILFunctionType>()->isPolymorphic() ||
558+
ObjCMethod->getType().castTo<SILFunctionType>()->hasOpenedExistential())
558559
return false;
559560

560561
// Don't outline in the outlined function.
@@ -608,7 +609,8 @@ bool BridgedProperty::matchInstSequence(SILBasicBlock::iterator It) {
608609
// Try to match without the load/strong_retain prefix.
609610
auto *CMI = dyn_cast<ObjCMethodInst>(It);
610611
if (!CMI || CMI->getFunction()->getLoweredFunctionType()->isPolymorphic() ||
611-
CMI->getType().castTo<SILFunctionType>()->isPolymorphic())
612+
CMI->getType().castTo<SILFunctionType>()->isPolymorphic() ||
613+
CMI->getType().castTo<SILFunctionType>()->hasOpenedExistential())
612614
return false;
613615
FirstInst = CMI;
614616
} else
@@ -1039,7 +1041,8 @@ bool ObjCMethodCall::matchInstSequence(SILBasicBlock::iterator I) {
10391041
ObjCMethod = dyn_cast<ObjCMethodInst>(I);
10401042
if (!ObjCMethod ||
10411043
ObjCMethod->getFunction()->getLoweredFunctionType()->isPolymorphic() ||
1042-
ObjCMethod->getType().castTo<SILFunctionType>()->isPolymorphic())
1044+
ObjCMethod->getType().castTo<SILFunctionType>()->isPolymorphic() ||
1045+
ObjCMethod->getType().castTo<SILFunctionType>()->hasOpenedExistential())
10431046
return false;
10441047

10451048
auto *Use = ObjCMethod->getSingleUse();

test/SILOptimizer/Inputs/Outliner.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,9 @@
2222
- (NSString*) doSomething;
2323
- (id) doSomething2 : (NSArray<NSString*>*) arr;
2424
@end
25+
26+
NS_ASSUME_NONNULL_BEGIN
27+
@protocol Treeish <NSObject>
28+
- (nullable NSArray *) treeishChildren;
29+
@end
30+
NS_ASSUME_NONNULL_END

test/SILOptimizer/outliner.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ public func testOutlining() {
5454
gizmo.doSomething(arr)
5555
}
5656

57+
// CHECK-LABEL: sil @$s8outliner9dontCrash1ayyp_tF : $@convention(thin) (@in_guaranteed Any) -> () {
58+
// CHECK: [[OBJ:%.*]] = open_existential_ref {{.*}} : $AnyObject to $@opened("{{.*}}") (AnyObject)
59+
// CHECK: [[METH:%.*]] = objc_method [[OBJ]] : $@opened("{{.*}}") (AnyObject), #Treeish.treeishChildren!1.foreign : <Self where Self : Treeish> (Self) -> () -> [Any]?
60+
// CHECK: [[RES:%.*]] = apply [[METH]]([[OBJ]]) : $@convention(objc_method)
61+
// CHECK: switch_enum [[RES]]
62+
5763
// CHECK-LABEL: sil shared [noinline] @$sSo5GizmoC14stringPropertySSSgvgToTeab_ : $@convention(thin) (@in_guaranteed Gizmo) -> @owned Optional<String>
5864
// CHECK: bb0(%0 : $*Gizmo):
5965
// CHECK: %1 = load %0 : $*Gizmo
@@ -175,3 +181,6 @@ extension Operation {
175181
}
176182
}
177183

184+
public func dontCrash(a: Any) {
185+
(a as AnyObject).treeishChildren()
186+
}

0 commit comments

Comments
 (0)