blob: e526e07bd74d9b65b0af212a6443301f2b6e0654 [file] [log] [blame]
// RUN: %target-swift-frontend -assume-parsing-unqualified-ownership-sil %s -emit-ir | %FileCheck %s
// REQUIRES: CPU=x86_64
import Swift
// CHECK-LABEL: @_T018field_type_vectors3FooVMn = hidden constant
// CHECK: %swift.type** (%swift.type*)* [[FOO_TYPES_ACCESSOR:@[A-Za-z0-9_]*]]
struct Foo {
var x: Int
}
// CHECK-LABEL: @_T018field_type_vectors3BarVMn = hidden constant
// CHECK: %swift.type** (%swift.type*)* [[BAR_TYPES_ACCESSOR:@[A-Za-z0-9_]*]]
// CHECK-LABEL: @_T018field_type_vectors3BarVMP = internal global
// -- There should be 4 words between the address point and the field type
// vector slot, with type %swift.type**
// CHECK: i64, i64, i64, %swift.type*, %swift.type**
struct Bar<T> {
var y: Int
}
// CHECK-LABEL: @_T018field_type_vectors3BasVMn = hidden constant
// CHECK: %swift.type** (%swift.type*)* [[BAS_TYPES_ACCESSOR:@[A-Za-z0-9_]*]]
// CHECK-LABEL: @_T018field_type_vectors3BasVMP = internal global
// -- There should be 6 words between the address point and the field type
// vector slot, with type %swift.type**
// CHECK: i64, i64, i64, %swift.type*, %swift.type*, %swift.type**
struct Bas<T, U> {
var foo: Foo
var bar: Bar<T>
}
// CHECK-LABEL: @_T018field_type_vectors3ZimCMn = hidden constant
// CHECK: %swift.type** (%swift.type*)* [[ZIM_TYPES_ACCESSOR:@[A-Za-z0-9_]*]]
// CHECK-LABEL: @_T018field_type_vectors3ZimCMP = internal global
// -- There should be 14 words between the address point and the field type
// vector slot, with type %swift.type**
// CHECK: i64, %swift.type*, %swift.opaque*, %swift.opaque*, i64, i32, i32, i32, i16, i16, i32, i32, i64, i8*, %swift.type*, %swift.type*, i8*, i64, i64, i64, %swift.type**
class Zim<T, U> {
var foo: Foo?
var bar: Bar<T>?
var bas: Bas<T, U>?
}
sil_vtable Zim {}
sil @_TFC18field_type_vectors3ZimcU___fMGS0_Q_Q0__FT_GS0_Q_Q0__ : $@convention(method) <T, U> (@owned Zim<T, U>) -> @owned Zim<T, U>
// CHECK-LABEL: @_T018field_type_vectors4ZangCMn = hidden constant
// CHECK: %swift.type** (%swift.type*)* [[ZANG_TYPES_ACCESSOR:@[A-Za-z0-9_]*]]
// CHECK-LABEL: @_T018field_type_vectors4ZangCMP = internal global
// -- There should be 16 words between the address point and the field type
// vector slot, with type %swift.type**
// CHECK: i64, %swift.type*, %swift.opaque*, %swift.opaque*, i64, i32, i32, i32, i16, i16, i32, i32, i64, i8*, %swift.type*, %swift.type*, i8*, i64, i64, i64, %swift.type*, i64, %swift.type**
class Zang<V>: Zim<V, V> {
var zung: Int = 0
}
sil_vtable Zang {}
sil @_TFC18field_type_vectors4ZangcU__fMGS0_Q__FT_GS0_Q__ : $@convention(method) <V> (@owned Zang<V>) -> @owned Zang<V>
// -- For storage-qualified fields, we just report the formal type.
class StorageQualified {
unowned var a: StorageQualified
weak var b: StorageQualified?
init(x: StorageQualified) {
a = x
b = x
}
}
sil_vtable StorageQualified {}
// CHECK: [[FOO_TYPE_VECTOR_SLOT:@.*Foo.*]] = private global %swift.type** null
// CHECK: define{{( protected)?}} private %swift.type** [[FOO_TYPES_ACCESSOR]](%swift.type* %Foo)
// CHECK: [[EXISTING:%.*]] = load %swift.type**, %swift.type*** [[FOO_TYPE_VECTOR_SLOT]]
// CHECK: [[IS_NULL:%.*]] = icmp eq %swift.type** [[EXISTING]], null
// CHECK: br i1 [[IS_NULL]], label %[[BUILD_FIELD_TYPES:.*]], label %[[DONE:.*]]
// CHECK: [[BUILD_FIELD_TYPES]]:
// CHECK: store {{.*}} @_T0SiN
// CHECK: cmpxchg {{.*}} [[FOO_TYPE_VECTOR_SLOT]]
// CHECK: define{{( protected)?}} private %swift.type** [[BAR_TYPES_ACCESSOR]](%swift.type* %"Bar<T>")
// CHECK: [[T0:%.*]] = bitcast %swift.type* %"Bar<T>" to %swift.type***
// -- 4 words between the address point and the slot
// CHECK: [[SLOT:%.*]] = getelementptr inbounds %swift.type**, %swift.type*** [[T0]], i32 4
// CHECK: load %swift.type**, %swift.type*** [[SLOT]], align 8
// CHECK: br
// CHECK-NOT: load %swift.type*,
// CHECK: store {{.*}} @_T0SiN
// CHECK: define{{( protected)?}} private %swift.type** [[BAS_TYPES_ACCESSOR]](%swift.type* %"Bas<T, U>")
// CHECK: [[T0:%.*]] = bitcast %swift.type* %"Bas<T, U>" to %swift.type***
// -- 6 words between the address point and the slot
// CHECK: [[SLOT:%.*]] = getelementptr inbounds %swift.type**, %swift.type*** [[T0]], i32 6
// CHECK: load %swift.type**, %swift.type*** [[SLOT]], align 8
// CHECK: br
// CHECK: store {{.*}} @_T018field_type_vectors3FooVMf
// CHECK: call %swift.type* @_T018field_type_vectors3BarVMa(%swift.type* %T)
// CHECK: define{{( protected)?}} private %swift.type** [[ZIM_TYPES_ACCESSOR]](%swift.type* %"Zim<T, U>")
// CHECK: [[T0:%.*]] = bitcast %swift.type* %"Zim<T, U>" to %swift.type***
// -- 14 words between the address point and the slot
// CHECK: [[SLOT:%.*]] = getelementptr inbounds %swift.type**, %swift.type*** [[T0]], i32 16
// CHECK: load %swift.type**, %swift.type*** [[SLOT]], align 8
// CHECK: define{{( protected)?}} private %swift.type** [[ZANG_TYPES_ACCESSOR]](%swift.type* %"Zang<V>")
// CHECK: [[T0:%.*]] = bitcast %swift.type* %"Zang<V>" to %swift.type***
// -- 16 words between the address point and the slot
// CHECK: [[SLOT:%.*]] = getelementptr inbounds %swift.type**, %swift.type*** [[T0]], i32 18
// CHECK: load %swift.type**, %swift.type*** [[SLOT]], align 8