Skip to content
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
3 changes: 2 additions & 1 deletion lib/SILOptimizer/IPO/LetPropertiesOpts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,8 @@ void LetPropertiesOpt::optimizeLetPropertyAccess(VarDecl *Property,
return;

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

LLVM_DEBUG(llvm::dbgs() << "Replacing access to property '" << *Property
Expand Down
2 changes: 2 additions & 0 deletions test/SILOptimizer/Inputs/let_properties_opts.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
@interface ObjcInterface: NSObject
@end

@interface ObjcInterfaceConstInit: NSObject
@end
11 changes: 11 additions & 0 deletions test/SILOptimizer/let_properties_opts_objc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,14 @@ public func testObjcInterface(_ x: ObjcInterface) -> Int {
return x.i
}

// Test optimization of a private constant. This constant must be declared in a separate type without other fields.
@_objcImplementation extension ObjcInterfaceConstInit {
private let constant: Int = 0

// CHECK-LABEL: sil hidden @$sSo22ObjcInterfaceConstInitC4testE0E15PrivateConstantSiyF : $@convention(method) (@guaranteed ObjcInterfaceConstInit) -> Int {
// CHECK: ref_element_addr %0 : $ObjcInterfaceConstInit, #ObjcInterfaceConstInit.constant
// CHECK-LABEL: } // end sil function '$sSo22ObjcInterfaceConstInitC4testE0E15PrivateConstantSiyF'
final func testPrivateConstant() -> Int {
return constant
}
}