Skip to content

Commit 98dabf9

Browse files
committed
Fix LetPropertiesOpt crash on @_objcImplementation extensions
Fixes rdar://115139065 (Swift Compiler; @_objcImplementation; crash in LetPropertiesOpt)
1 parent 126022f commit 98dabf9

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

lib/SILOptimizer/IPO/LetPropertiesOpts.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,8 @@ void LetPropertiesOpt::optimizeLetPropertyAccess(VarDecl *Property,
239239
return;
240240

241241
auto *Ty = dyn_cast<NominalTypeDecl>(Property->getDeclContext());
242-
if (SkipTypeProcessing.count(Ty))
242+
// Ty is null for properties declared inside an extension of an ObjC type.
243+
if (!Ty || SkipTypeProcessing.count(Ty))
243244
return;
244245

245246
LLVM_DEBUG(llvm::dbgs() << "Replacing access to property '" << *Property

test/SILOptimizer/Inputs/let_properties_opts.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
@interface ObjcInterface: NSObject
44
@end
55

6+
@interface ObjcInterfaceConstInit: NSObject
7+
@end

test/SILOptimizer/let_properties_opts_objc.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,19 @@
1111

1212
// CHECK-LABEL: sil @$s4test0A13ObjcInterfaceySiSo0bC0CF
1313
// CHECK: ref_element_addr [immutable] %0 : $ObjcInterface, #ObjcInterface.i
14-
// CHECK: } // end sil function '$s4test0A13ObjcInterfaceySiSo0bC0CF'
14+
// CHECK-LABEL: } // end sil function '$s4test0A13ObjcInterfaceySiSo0bC0CF'
1515
public func testObjcInterface(_ x: ObjcInterface) -> Int {
1616
return x.i
1717
}
1818

19+
// Test optimization of a private constant. This constant must be declared in a separate type without other fields.
20+
@_objcImplementation extension ObjcInterfaceConstInit {
21+
private let constant: Int = 0
22+
23+
// CHECK-LABEL: sil hidden @$sSo22ObjcInterfaceConstInitC4testE0E15PrivateConstantSiyF : $@convention(method) (@guaranteed ObjcInterfaceConstInit) -> Int {
24+
// CHECK: ref_element_addr [immutable] %0 : $ObjcInterfaceConstInit, #ObjcInterfaceConstInit.constant
25+
// CHECK-LABEL: } // end sil function '$sSo22ObjcInterfaceConstInitC4testE0E15PrivateConstantSiyF'
26+
final func testPrivateConstant() -> Int {
27+
return constant
28+
}
29+
}

0 commit comments

Comments
 (0)