Skip to content

Commit c86a4cc

Browse files
authored
Merge pull request #13210 from aschwaighofer/outliner_objc_generic_methods
2 parents f8fb6ac + a6504fb commit c86a4cc

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

lib/SILOptimizer/Transforms/Outliner.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,8 @@ bool BridgedProperty::matchMethodCall(SILBasicBlock::iterator It) {
427427
SILValue Instance =
428428
FirstInst != ObjCMethod ? FirstInst : ObjCMethod->getOperand();
429429
if (!ObjCMethod || !ObjCMethod->hasOneUse() ||
430-
ObjCMethod->getOperand() != Instance)
430+
ObjCMethod->getOperand() != Instance ||
431+
ObjCMethod->getFunction()->getLoweredFunctionType()->isPolymorphic())
431432
return false;
432433

433434
// Don't outline in the outlined function.
@@ -568,7 +569,7 @@ bool BridgedProperty::matchInstSequence(SILBasicBlock::iterator It) {
568569
if (!Load) {
569570
// Try to match without the load/strong_retain prefix.
570571
auto *CMI = dyn_cast<ObjCMethodInst>(It);
571-
if (!CMI)
572+
if (!CMI || CMI->getFunction()->getLoweredFunctionType()->isPolymorphic())
572573
return false;
573574
FirstInst = CMI;
574575
} else
@@ -1104,7 +1105,8 @@ bool ObjCMethodCall::matchInstSequence(SILBasicBlock::iterator I) {
11041105
clearState();
11051106

11061107
ObjCMethod = dyn_cast<ObjCMethodInst>(I);
1107-
if (!ObjCMethod)
1108+
if (!ObjCMethod ||
1109+
ObjCMethod->getFunction()->getLoweredFunctionType()->isPolymorphic())
11081110
return false;
11091111
auto *Use = ObjCMethod->getSingleUse();
11101112
if (!Use)

test/SILOptimizer/Inputs/Outliner.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
#import <Foundation/Foundation.h>
22

3+
@protocol Proto
4+
- (id)requirement;
5+
@end
6+
37
@interface Gizmo : NSObject
48
@property (nonatomic)NSString *stringProperty;
59
- (NSString*) modifyString: (NSString *)str withNumber: (NSInteger) num withFoobar: (id)foobar;
610
- (id) doSomething : (NSArray<NSString*>*) arr;
711
@end
812

13+
@interface Gizmo2<ObjectType: id<Proto>> : NSObject
14+
- (NSString*) doSomething;
15+
@end
16+
917

test/SILOptimizer/outliner.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,9 @@ public func testOutlining() {
134134
// CHECK: %7 = apply %2(%6, %1) : $@convention(objc_method) (Optional<NSArray>, Gizmo) -> @autoreleased Optional<AnyObject>
135135
// CHECK: strong_release %4 : $NSArray
136136
// CHECK: return %7 : $Optional<AnyObject>
137+
138+
public func dontCrash<T: Proto>(x : Gizmo2<T>) {
139+
let s = x.doSomething()
140+
print(s)
141+
142+
}

0 commit comments

Comments
 (0)