Skip to content

Commit f1f75ca

Browse files
Merge pull request #26931 from aschwaighofer/outliner_fix
Outliner fix: Make sure the enum actually has an operand before we access it
2 parents 6fcbb40 + 6842134 commit f1f75ca

File tree

3 files changed

+56
-1
lines changed

3 files changed

+56
-1
lines changed

lib/SILOptimizer/Transforms/Outliner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ BridgedArgument BridgedArgument::match(unsigned ArgIdx, SILValue Arg,
737737
// release_value %17 : $Optional<NSString>
738738
//
739739
auto *Enum = dyn_cast<EnumInst>(Arg);
740-
if (!Enum)
740+
if (!Enum || !Enum->hasOperand())
741741
return BridgedArgument();
742742

743743
if (SILBasicBlock::iterator(Enum) == Enum->getParent()->begin())

test/SILOptimizer/Inputs/Outliner.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,37 @@
2323
- (id) doSomething2 : (NSArray<NSString*>*) arr;
2424
@end
2525

26+
typedef NS_ENUM(NSUInteger, MyEventType) {
27+
MyEventTypeA = 1,
28+
MyEventTypeB = 2
29+
};
30+
31+
@interface MyWindow : NSObject
32+
@property NSInteger windowNumber;
33+
@end
34+
35+
@interface MyView : NSObject
36+
@property (nonatomic, nullable, readonly, strong) MyWindow *window;
37+
@end
38+
39+
typedef struct MyPoint {
40+
NSInteger x;
41+
NSInteger y;
42+
} MyPoint;
43+
44+
@interface MyGraphicsContext : NSObject
45+
@end
46+
47+
@interface MyEvent : NSObject
48+
+ (nullable MyEvent *)mouseEventWithType:(MyEventType)type
49+
location:(MyPoint)pt
50+
windowNumber:(NSInteger)wNum
51+
context:(nullable MyGraphicsContext * __unused)context
52+
eventNumber:(NSInteger)eNum
53+
clickCount:(NSInteger)cnt
54+
pressure:(float)pressure;
55+
@end
56+
2657
NS_ASSUME_NONNULL_BEGIN
2758
@protocol Treeish <NSObject>
2859
- (nullable NSArray *) treeishChildren;

test/SILOptimizer/outliner.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,3 +184,27 @@ extension Operation {
184184
public func dontCrash(a: Any) {
185185
(a as AnyObject).treeishChildren()
186186
}
187+
188+
public class Foo : NSObject {
189+
var x: MyView? = nil
190+
191+
public func dontCrash(_ pt: MyPoint) -> Bool {
192+
guard let somView = x,
193+
let window = somView.window else {
194+
return false
195+
}
196+
197+
guard let event = MyEvent.mouseEvent(with: .A,
198+
location: pt,
199+
windowNumber: window.windowNumber,
200+
context: nil,
201+
eventNumber: 0,
202+
clickCount: 1,
203+
pressure:1) else {
204+
print("failure")
205+
return false
206+
}
207+
print(event)
208+
return true
209+
}
210+
}

0 commit comments

Comments
 (0)