Skip to content

Commit 69e8ea7

Browse files
authored
Merge pull request swiftlang#70115 from atrick/510-fix-let-props
[5.10] Fix LetPropertiesOpt crash on @_objcImplementation extensions
2 parents 70e581e + a49c788 commit 69e8ea7

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,14 @@ 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 %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)