Skip to content

Commit

Permalink
Merge pull request swiftlang#26931 from aschwaighofer/outliner_fix
Browse files Browse the repository at this point in the history
Outliner fix: Make sure the enum actually has an operand before we access it
  • Loading branch information
aschwaighofer authored Aug 29, 2019
2 parents 6fcbb40 + 6842134 commit f1f75ca
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/SILOptimizer/Transforms/Outliner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ BridgedArgument BridgedArgument::match(unsigned ArgIdx, SILValue Arg,
// release_value %17 : $Optional<NSString>
//
auto *Enum = dyn_cast<EnumInst>(Arg);
if (!Enum)
if (!Enum || !Enum->hasOperand())
return BridgedArgument();

if (SILBasicBlock::iterator(Enum) == Enum->getParent()->begin())
Expand Down
31 changes: 31 additions & 0 deletions test/SILOptimizer/Inputs/Outliner.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,37 @@
- (id) doSomething2 : (NSArray<NSString*>*) arr;
@end

typedef NS_ENUM(NSUInteger, MyEventType) {
MyEventTypeA = 1,
MyEventTypeB = 2
};

@interface MyWindow : NSObject
@property NSInteger windowNumber;
@end

@interface MyView : NSObject
@property (nonatomic, nullable, readonly, strong) MyWindow *window;
@end

typedef struct MyPoint {
NSInteger x;
NSInteger y;
} MyPoint;

@interface MyGraphicsContext : NSObject
@end

@interface MyEvent : NSObject
+ (nullable MyEvent *)mouseEventWithType:(MyEventType)type
location:(MyPoint)pt
windowNumber:(NSInteger)wNum
context:(nullable MyGraphicsContext * __unused)context
eventNumber:(NSInteger)eNum
clickCount:(NSInteger)cnt
pressure:(float)pressure;
@end

NS_ASSUME_NONNULL_BEGIN
@protocol Treeish <NSObject>
- (nullable NSArray *) treeishChildren;
Expand Down
24 changes: 24 additions & 0 deletions test/SILOptimizer/outliner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,27 @@ extension Operation {
public func dontCrash(a: Any) {
(a as AnyObject).treeishChildren()
}

public class Foo : NSObject {
var x: MyView? = nil

public func dontCrash(_ pt: MyPoint) -> Bool {
guard let somView = x,
let window = somView.window else {
return false
}

guard let event = MyEvent.mouseEvent(with: .A,
location: pt,
windowNumber: window.windowNumber,
context: nil,
eventNumber: 0,
clickCount: 1,
pressure:1) else {
print("failure")
return false
}
print(event)
return true
}
}

0 comments on commit f1f75ca

Please sign in to comment.