Skip to content

Commit edecd95

Browse files
Merge pull request #13855 from aschwaighofer/swift-4.1-branch_outliner_generic_objc_class_fix
[4.1] Outliner: Can't handle generic ObjC classes
2 parents 6b70d5d + 3f8f0a7 commit edecd95

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

lib/SILOptimizer/Transforms/Outliner.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,8 @@ bool BridgedProperty::matchMethodCall(SILBasicBlock::iterator It) {
428428
FirstInst != ObjCMethod ? FirstInst : ObjCMethod->getOperand();
429429
if (!ObjCMethod || !ObjCMethod->hasOneUse() ||
430430
ObjCMethod->getOperand() != Instance ||
431-
ObjCMethod->getFunction()->getLoweredFunctionType()->isPolymorphic())
431+
ObjCMethod->getFunction()->getLoweredFunctionType()->isPolymorphic() ||
432+
ObjCMethod->getType().castTo<SILFunctionType>()->isPolymorphic())
432433
return false;
433434

434435
// Don't outline in the outlined function.
@@ -569,7 +570,8 @@ bool BridgedProperty::matchInstSequence(SILBasicBlock::iterator It) {
569570
if (!Load) {
570571
// Try to match without the load/strong_retain prefix.
571572
auto *CMI = dyn_cast<ObjCMethodInst>(It);
572-
if (!CMI || CMI->getFunction()->getLoweredFunctionType()->isPolymorphic())
573+
if (!CMI || CMI->getFunction()->getLoweredFunctionType()->isPolymorphic() ||
574+
CMI->getType().castTo<SILFunctionType>()->isPolymorphic())
573575
return false;
574576
FirstInst = CMI;
575577
} else
@@ -608,7 +610,6 @@ bool BridgedProperty::matchInstSequence(SILBasicBlock::iterator It) {
608610
if (!Release || NumUses != 4)
609611
return false;
610612
}
611-
612613
return true;
613614
}
614615

@@ -1106,8 +1107,10 @@ bool ObjCMethodCall::matchInstSequence(SILBasicBlock::iterator I) {
11061107

11071108
ObjCMethod = dyn_cast<ObjCMethodInst>(I);
11081109
if (!ObjCMethod ||
1109-
ObjCMethod->getFunction()->getLoweredFunctionType()->isPolymorphic())
1110+
ObjCMethod->getFunction()->getLoweredFunctionType()->isPolymorphic() ||
1111+
ObjCMethod->getType().castTo<SILFunctionType>()->isPolymorphic())
11101112
return false;
1113+
11111114
auto *Use = ObjCMethod->getSingleUse();
11121115
if (!Use)
11131116
return false;

test/SILOptimizer/Inputs/Outliner.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,11 @@
1414
- (NSString*) doSomething;
1515
@end
1616

17+
@protocol FooProto <NSObject>
18+
@end
1719

20+
@protocol SomeGenericClass <FooProto>
21+
@property (nonatomic, nullable, readonly, strong) NSString *version;
22+
- (NSString*) doSomething;
23+
- (id) doSomething2 : (NSArray<NSString*>*) arr;
24+
@end

test/SILOptimizer/outliner.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,17 @@ public func dontCrash<T: Proto>(x : Gizmo2<T>) {
140140
print(s)
141141

142142
}
143+
144+
public func dontCrash2(_ c: SomeGenericClass) -> Bool {
145+
guard let str = c.version else {
146+
return false
147+
}
148+
guard let str2 = c.doSomething() else {
149+
return false
150+
}
151+
152+
let arr = [ "foo", "bar"]
153+
c.doSomething2(arr)
154+
155+
return true
156+
}

0 commit comments

Comments
 (0)