mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
62 lines
2.2 KiB
Plaintext
62 lines
2.2 KiB
Plaintext
|
|
// RUN: %empty-directory(%t)
|
|
// RUN: %{python} %utils/chex.py < %s > %t/keypaths_objc.sil
|
|
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -emit-ir %t/keypaths_objc.sil | %FileCheck %t/keypaths_objc.sil --check-prefix=CHECK --check-prefix=CHECK-%target-ptrsize
|
|
// REQUIRES: objc_interop
|
|
|
|
import Swift
|
|
import Foundation
|
|
|
|
class C: NSObject {
|
|
@objc dynamic var x: NSString { get }
|
|
@_hasStorage final var stored: Int
|
|
override init()
|
|
}
|
|
|
|
sil_vtable C {}
|
|
|
|
sil @x_get : $@convention(keypath_accessor_getter) (@in_guaranteed C) -> @out NSString
|
|
|
|
// CHECK: [[KEYPATH_A:@keypath(\..*)?]] = private global
|
|
// -- computed, get-only, function-instantiated identifier
|
|
// CHECK-SAME: <i32 0x0200_0001>,
|
|
// CHECK-SAME: ptr [[SELECTOR_FN:@[A-Za-z0-9_.]+]] to
|
|
|
|
// CHECK: [[KEYPATH_B:@keypath(\..*)?]] = private global
|
|
// -- class mutable stored property with indirect offset
|
|
// CHECK-SAME: <i32 0x03fffffd>,
|
|
// CHECK-SAME: @"$s13keypaths_objc1CC6storedSivpWvd"
|
|
|
|
// CHECK-LABEL: define swiftcc void @objc_only_property()
|
|
sil @objc_only_property : $@convention(thin) () -> () {
|
|
entry:
|
|
// CHECK: call ptr @swift_getKeyPath({{.*}} [[KEYPATH_A]]
|
|
%a = keypath $KeyPath<C, NSString>, (objc "x"; root $C; gettable_property $NSString, id #C.x!getter.foreign, getter @x_get : $@convention(keypath_accessor_getter) (@in_guaranteed C) -> @out NSString)
|
|
strong_retain %a : $KeyPath<C, NSString>
|
|
unreachable
|
|
}
|
|
|
|
sil hidden @$s13keypaths_objc1CC1xSo8NSStringCvgTo : $@convention(objc_method) (@guaranteed C) -> NSString {
|
|
entry(%0 : $C):
|
|
unreachable
|
|
}
|
|
|
|
sil hidden @$s13keypaths_objc1CCACycfcTo : $@convention(objc_method) (@objc_metatype C.Type) -> @owned C {
|
|
entry(%0 : $@objc_metatype C.Type):
|
|
unreachable
|
|
}
|
|
|
|
// CHECK: define linkonce_odr hidden ptr [[SELECTOR_FN]]
|
|
// CHECK-NEXT: entry:
|
|
// CHECK-NEXT: %1 = load {{.*}}selector(x)
|
|
// CHECK-NEXT: ret ptr %1
|
|
|
|
// CHECK-LABEL: define swiftcc void @objc_stored_property()
|
|
sil @objc_stored_property : $@convention(thin) () -> () {
|
|
entry:
|
|
// CHECK: call ptr @swift_getKeyPath({{.*}} [[KEYPATH_B]]
|
|
%b = keypath $KeyPath<C, Int>, (objc "stored"; root $C; stored_property #C.stored : $Int)
|
|
strong_retain %b : $KeyPath<C, Int>
|
|
unreachable
|
|
}
|