Skip to content

Outliner fix: Make sure the enum actually has an operand before we access it #26931

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}