Skip to content

Commit d442155

Browse files
committed
LetPropertiesOpts: don't crash for properties in ObjC extensions
rdar://103381746
1 parent 1e1126c commit d442155

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

lib/SILOptimizer/IPO/LetPropertiesOpts.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,10 @@ static bool isAssignableExternally(VarDecl *Property, SILModule *Module) {
361361

362362
auto *Ty = dyn_cast<NominalTypeDecl>(Property->getDeclContext());
363363

364+
// Check for "unusual" decl contexts, e.g. ObjC extensions.
365+
if (!Ty)
366+
return true;
367+
364368
// Initializer for a let property of a class cannot exist externally.
365369
// It cannot be defined by an extension or a derived class.
366370
if (isa<ClassDecl>(Ty))
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#import <Foundation/NSObject.h>
2+
3+
@interface ObjcInterface: NSObject
4+
@end
5+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: %target-swift-frontend -module-name test -primary-file %s -import-objc-header %S/Inputs/let_properties_opts.h -O -wmo -emit-sil | %FileCheck %s
2+
3+
// REQUIRES: objc_interop
4+
5+
// CHECK-LABEL: @_objcImplementation extension ObjcInterface
6+
@_objcImplementation extension ObjcInterface {
7+
final public let i: Int
8+
}
9+
10+
// Check that it doesn't crash with properties in ObjC extensions
11+
12+
// CHECK-LABEL: sil @$s4test0A13ObjcInterfaceySiSo0bC0CF
13+
// CHECK: ref_element_addr %0 : $ObjcInterface, #ObjcInterface.i
14+
// CHECK: } // end sil function '$s4test0A13ObjcInterfaceySiSo0bC0CF'
15+
public func testObjcInterface(_ x: ObjcInterface) -> Int {
16+
return x.i
17+
}
18+

0 commit comments

Comments
 (0)