Skip to content

Commit 4eb94a5

Browse files
authored
Merge pull request #28681 from aschwaighofer/outliner_fix_57757241
Outliner: Verify that getBridgeFromObjectiveC and getBridgeToObjectiveC return a valid SILDeclRef
2 parents 2e17867 + 95475aa commit 4eb94a5

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

lib/SILOptimizer/Transforms/Outliner.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,8 @@ static bool matchSwitch(SwitchInfo &SI, SILInstruction *Inst,
492492
auto *BridgeFun = FunRef->getInitiallyReferencedFunction();
493493
auto *SwiftModule = BridgeFun->getModule().getSwiftModule();
494494
auto bridgeWitness = getBridgeFromObjectiveC(NativeType, SwiftModule);
495-
if (BridgeFun->getName() != bridgeWitness.mangle())
495+
if (bridgeWitness == SILDeclRef() ||
496+
BridgeFun->getName() != bridgeWitness.mangle())
496497
return false;
497498

498499
// %41 = enum $Optional<String>, #Optional.some!enumelt.1, %40 : $String
@@ -809,7 +810,8 @@ BridgedArgument BridgedArgument::match(unsigned ArgIdx, SILValue Arg,
809810
auto *BridgeFun = FunRef->getInitiallyReferencedFunction();
810811
auto *SwiftModule = BridgeFun->getModule().getSwiftModule();
811812
auto bridgeWitness = getBridgeToObjectiveC(NativeType, SwiftModule);
812-
if (BridgeFun->getName() != bridgeWitness.mangle())
813+
if (bridgeWitness == SILDeclRef() ||
814+
BridgeFun->getName() != bridgeWitness.mangle())
813815
return BridgedArgument();
814816

815817
return BridgedArgument(ArgIdx, FunRef, BridgeCall, Enum, BridgedValueRelease,

test/SILOptimizer/Inputs/Outliner.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ typedef NS_ENUM(NSUInteger, MyEventType) {
3434

3535
@interface MyView : NSObject
3636
@property (nonatomic, nullable, readonly, strong) MyWindow *window;
37+
@property (nonatomic, nullable, strong) MyWindow *window2;
3738
@end
3839

3940
typedef struct MyPoint {

test/SILOptimizer/outliner.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,3 +222,20 @@ public func testCalendar() {
222222
let formatter = DateFormatter()
223223
formatter.calendar = Calendar(identifier: .gregorian)
224224
}
225+
226+
open class Test
227+
{
228+
@inline(never)
229+
public func getWindow() -> MyWindow
230+
{
231+
return MyWindow()
232+
}
233+
234+
public func testDontCrash() -> MyView
235+
{
236+
237+
let view = MyView()
238+
view.window2 = getWindow()
239+
return view
240+
}
241+
}

0 commit comments

Comments
 (0)