1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272
|
// RUN: %empty-directory(%t)
// RUN: %{python} %utils/chex.py < %s > %t/raw_layout.sil
// RUN: %target-swift-frontend -enable-experimental-feature RawLayout -emit-ir -disable-availability-checking -I %S/Inputs -cxx-interoperability-mode=upcoming-swift %t/raw_layout.sil | %FileCheck %t/raw_layout.sil --check-prefix=CHECK --check-prefix=CHECK-%target-ptrsize
import Builtin
import Swift
import RawLayoutCXX
// CHECK-LABEL: @"$s{{[A-Za-z0-9_]*}}4LockVWV" = {{.*}} %swift.vwtable
// size
// CHECK-SAME: , {{i64|i32}} 4
// stride
// CHECK-SAME: , {{i64|i32}} 4
// flags: alignment 3, noncopyable, non-bitwise-borrowable
// CHECK-SAME: , <i32 0x1800003>
@_rawLayout(size: 4, alignment: 4)
struct Lock: ~Copyable { }
struct PaddedStride {
var x: Int32
var y: Int8
}
// CHECK-LABEL: @"$s{{[A-Za-z0-9_]*}}16LikePaddedStrideVWV" = {{.*}} %swift.vwtable
// size
// CHECK-SAME: , {{i64|i32}} 5
// stride
// CHECK-SAME: , {{i64|i32}} 8
// flags: alignment 3, noncopyable, non-bitwise-borrowable
// CHECK-SAME: , <i32 0x1800003>
@_rawLayout(like: PaddedStride)
struct LikePaddedStride: ~Copyable {}
// CHECK-LABEL: @"$s{{[A-Za-z0-9_]*}}22LikePaddedStrideArray1VWV" = {{.*}} %swift.vwtable
// size
// CHECK-SAME: , {{i64|i32}} 8
// stride
// CHECK-SAME: , {{i64|i32}} 8
// flags: alignment 3, noncopyable, non-bitwise-borrowable
// CHECK-SAME: , <i32 0x1800003>
@_rawLayout(likeArrayOf: PaddedStride, count: 1)
struct LikePaddedStrideArray1: ~Copyable {}
// CHECK-LABEL: @"$s{{[A-Za-z0-9_]*}}22LikePaddedStrideArray2VWV" = {{.*}} %swift.vwtable
// size
// CHECK-SAME: , {{i64|i32}} 16
// stride
// CHECK-SAME: , {{i64|i32}} 16
// flags: alignment 3, noncopyable, non-bitwise-borrowable, (on 32-bit platforms) not storable inline
// CHECK-64-SAME: , <i32 0x1800003>
// CHECK-32-SAME: , <i32 0x1820003>
@_rawLayout(likeArrayOf: PaddedStride, count: 2)
struct LikePaddedStrideArray2: ~Copyable {}
// CHECK-LABEL: @"$s{{[A-Za-z0-9_]*}}9KeymasterVWV" = {{.*}} %swift.vwtable
// size
// CHECK-SAME: , {{i64|i32}} 12
// stride
// CHECK-SAME: , {{i64|i32}} 12
// flags: alignment 3, noncopyable, non-bitwise-borrowable
// CHECK-SAME: , <i32 0x1800003>
struct Keymaster: ~Copyable {
let lock1: Lock
let lock2: Lock
let lock3: Lock
}
// Dependent Layouts:
// These types have their layouts all zeroed out and will be fixed up at
// runtime.
// CHECK-LABEL: @"$s{{[A-Za-z0-9_]*}}4CellVWV" = {{.*}} %swift.vwtable
// size
// CHECK-SAME: , {{i64|i32}} 0
// stride
// CHECK-SAME: , {{i64|i32}} 0
// flags: alignment 0, incomplete
// CHECK-SAME: , <i32 0x400000>
@_rawLayout(like: T)
struct Cell<T>: ~Copyable {}
// CHECK-LABEL: @"$s{{[A-Za-z0-9_]*}}10PaddedCellVWV" = {{.*}} %swift.vwtable
// size
// CHECK-SAME: , {{i64|i32}} 0
// stride
// CHECK-SAME: , {{i64|i32}} 0
// flags: alignment 0, incomplete
// CHECK-SAME: , <i32 0x400000>
@_rawLayout(likeArrayOf: T, count: 1)
struct PaddedCell<T>: ~Copyable {}
// CHECK-LABEL: @"$s{{[A-Za-z0-9_]*}}14SmallVectorBufVWV" = {{.*}} %swift.vwtable
// size
// CHECK-SAME: , {{i64|i32}} 0
// stride
// CHECK-SAME: , {{i64|i32}} 0
// flags: alignment 0, incomplete
// CHECK-SAME: , <i32 0x400000>
@_rawLayout(likeArrayOf: T, count: 8)
struct SmallVectorBuf<T>: ~Copyable {}
// CHECK-LABEL: @"$s{{[A-Za-z0-9_]*}}14SmallVectorOf3VWV" = {{.*}} %swift.vwtable
// size
// CHECK-SAME: , {{i64|i32}} 0
// stride
// CHECK-SAME: , {{i64|i32}} 0
// flags: alignment 0, incomplete
// CHECK-SAME: , <i32 0x400000>
@_rawLayout(likeArrayOf: T, count: 3)
struct SmallVectorOf3<T>: ~Copyable {}
// CHECK-LABEL: @"$s{{[A-Za-z0-9_]*}}8UsesCellVWV" = {{.*}} %swift.vwtable
// size
// CHECK-SAME: , {{i64|i32}} 8
// stride
// CHECK-SAME: , {{i64|i32}} 8
// flags: alignment 3, noncopyable, non-bitwise-borrowable
// CHECK-SAME: , <i32 0x1800003>
struct UsesCell: ~Copyable {
let someCondition: Bool
let specialInt: Cell<Int32>
}
// CHECK-LABEL: @"$s{{[A-Za-z0-9_]*}}13BufferOf3BoolVWV" = {{.*}} %swift.vwtable
// size
// CHECK-SAME: , {{i64|i32}} 3
// stride
// CHECK-SAME: , {{i64|i32}} 3
// flags: alignment 0, noncopyable, non-bitwise-borrowable
// CHECK-SAME: , <i32 0x1800000>
struct BufferOf3Bool: ~Copyable {
let buffer: SmallVectorOf3<Bool>
}
// CHECK-LABEL: @"$s{{[A-Za-z0-9_]*}}9BadBufferVWV" = {{.*}} %swift.vwtable
// size
// CHECK-SAME: , {{i64|i32}} 48
// stride
// CHECK-SAME: , {{i64|i32}} 48
// flags: alignment 7, noncopyable, non-bitwise-borrowable, is not inline
// CHECK-SAME: , <i32 0x1820007>
struct BadBuffer: ~Copyable {
let buffer: SmallVectorOf3<Int64?>
}
// Raw Layout types that move like their like type
// CHECK-LABEL: @"$s{{[A-Za-z0-9_]*}}19CellThatMovesAsLikeVWV" = {{.*}} %swift.vwtable
// initializeWithTake
// CHECK-SAME: , ptr @"$s10raw_layout19CellThatMovesAsLikeVwtk
// assignWithTake
// CHECK-SAME: , ptr @"$s10raw_layout19CellThatMovesAsLikeVwta
// size
// CHECK-SAME: , {{i64|i32}} 0
// stride
// CHECK-SAME: , {{i64|i32}} 0
// flags: alignment 0, incomplete
// CHECK-SAME: , <i32 0x400000>
@_rawLayout(like: T, movesAsLike)
struct CellThatMovesAsLike<T>: ~Copyable {}
// CHECK-LABEL: @"$s{{[A-Za-z0-9_]*}}18ConcreteMoveAsLikeVWV" = {{.*}} %swift.vwtable
// initializeWithTake
// CHECK-SAME: , ptr @"$s10raw_layout18ConcreteMoveAsLikeVwtk
// assignWithTake
// CHECK-SAME: , ptr @"$s10raw_layout18ConcreteMoveAsLikeVwta
// size
// CHECK-SAME: , {{i64|i32}} 1
// stride
// CHECK-SAME: , {{i64|i32}} 1
// flags: not copyable, not bitwise takable, not pod, not inline
// CHECK-SAME: , <i32 0x930000>
struct ConcreteMoveAsLike: ~Copyable {
let cell: CellThatMovesAsLike<NonBitwiseTakableCXXType>
}
// CHECK-LABEL: @"$s{{[A-Za-z0-9_]*}}21ConcreteIntMoveAsLikeVWV" = {{.*}} %swift.vwtable
// initializeWithTake
// CHECK-SAME: , ptr @__swift_memcpy4_4
// assignWithTake
// CHECK-SAME: , ptr @__swift_memcpy4_4
// size
// CHECK-SAME: , {{i64|i32}} 4
// stride
// CHECK-SAME: , {{i64|i32}} 4
// flags: alignment 3, not copyable, not bitwise-borrowable
// CHECK-SAME: , <i32 0x1800003>
struct ConcreteIntMoveAsLike: ~Copyable {
let cell: CellThatMovesAsLike<Int32>
}
sil @use_lock : $@convention(thin) (@in_guaranteed Lock) -> () {
entry(%L: $*Lock):
return undef : $()
}
sil @use_keymaster_locks : $@convention(thin) (@in_guaranteed Keymaster) -> () {
entry(%K: $*Keymaster):
%f = function_ref @use_lock : $@convention(thin) (@in_guaranteed Lock) -> ()
%a = struct_element_addr %K : $*Keymaster, #Keymaster.lock1
apply %f(%a) : $@convention(thin) (@in_guaranteed Lock) -> ()
%b = struct_element_addr %K : $*Keymaster, #Keymaster.lock2
apply %f(%b) : $@convention(thin) (@in_guaranteed Lock) -> ()
%c = struct_element_addr %K : $*Keymaster, #Keymaster.lock2
apply %f(%c) : $@convention(thin) (@in_guaranteed Lock) -> ()
return undef : $()
}
// CHECK: define {{.*}}swiftcc ptr @get_cell_addr(ptr %"Cell<T>", ptr {{.*}} swiftself [[SELF:%.*]])
// CHECK-NEXT: entry:
// CHECK-NEXT: ret ptr [[SELF]]
sil @get_cell_addr : $@convention(method) <T> (@in_guaranteed Cell<T>) -> UnsafeMutablePointer<T> {
entry(%0 : $*Cell<T>):
%1 = builtin "addressOfRawLayout"(%0 : $*Cell<T>) : $Builtin.RawPointer
%2 = struct $UnsafeMutablePointer<T> (%1 : $Builtin.RawPointer)
return %2 : $UnsafeMutablePointer<T>
}
// Dependent layout metadata initialization:
// Cell<T>
// CHECK-LABEL: define {{.*}} swiftcc %swift.metadata_response @"$s{{[A-Za-z0-9_]*}}4CellVMr"(ptr %"Cell<T>", ptr {{.*}}, ptr {{.*}})
// CHECK: [[T_ADDR:%.*]] = getelementptr inbounds ptr, ptr %"Cell<T>", {{i64|i32}} 2
// CHECK-NEXT: [[T:%.*]] = load ptr, ptr [[T_ADDR]]
// CHECK-NEXT: [[RESPONSE:%.*]] = call swiftcc %swift.metadata_response @swift_checkMetadataState({{i64|i32}} 319, ptr [[T]])
// CHECK-NEXT: [[T:%.*]] = extractvalue %swift.metadata_response [[RESPONSE]], 0
// CHECK: [[T_VWT_ADDR:%.*]] = getelementptr inbounds ptr, ptr [[T]], {{i64|i32}} -1
// CHECK-NEXT: {{%.*}} = load ptr, ptr [[T_VWT_ADDR]]
// CHECK: [[T_LAYOUT:%.*]] = getelementptr inbounds ptr, ptr {{%.*}}, i32 8
// CHECK-NEXT: call void @swift_initRawStructMetadata(ptr %"Cell<T>", {{i64|i32}} 0, ptr [[T_LAYOUT]], {{i64|i32}} -1)
// PaddedCell<T>
// CHECK-LABEL: define {{.*}} swiftcc %swift.metadata_response @"$s{{[A-Za-z0-9_]*}}10PaddedCellVMr"(ptr %"PaddedCell<T>", ptr {{.*}}, ptr {{.*}})
// CHECK: call void @swift_initRawStructMetadata(ptr %"PaddedCell<T>", {{i64|i32}} 0, ptr {{%.*}}, {{i64|i32}} 1)
// SmallVectorBuf<T>
// CHECK-LABEL: define {{.*}} swiftcc %swift.metadata_response @"$s{{[A-Za-z0-9_]*}}14SmallVectorBufVMr"(ptr %"SmallVectorBuf<T>", ptr {{.*}}, ptr {{.*}})
// CHECK: call void @swift_initRawStructMetadata(ptr %"SmallVectorBuf<T>", {{i64|i32}} 0, ptr {{%.*}}, {{i64|i32}} 8)
// Ensure that 'movesAsLike' is correctly calling the underlying type's move constructor
// CellThatMovesAsLike<T> initializeWithTake
// CHECK-LABEL: define {{.*}} ptr @"$s10raw_layout19CellThatMovesAsLikeVwtk"(ptr {{.*}} %dest, ptr {{.*}} %src, ptr %"CellThatMovesAsLike<T>")
// CHECK: [[T_ADDR:%.*]] = getelementptr inbounds ptr, ptr %"CellThatMovesAsLike<T>", {{i64|i32}} 2
// CHECK-NEXT: [[T:%.*]] = load ptr, ptr [[T_ADDR]]
// CHECK: {{%.*}} = call ptr %InitializeWithTake(ptr {{.*}} %dest, ptr {{.*}} %src, ptr [[T]])
// CellThatMovesAsLike<T> assignWithTake
// CHECK-LABEL: define {{.*}} ptr @"$s10raw_layout19CellThatMovesAsLikeVwta"(ptr {{.*}} %dest, ptr {{.*}} %src, ptr %"CellThatMovesAsLike<T>")
// CHECK: [[T_ADDR:%.*]] = getelementptr inbounds ptr, ptr %"CellThatMovesAsLike<T>", {{i64|i32}} 2
// CHECK-NEXT: [[T:%.*]] = load ptr, ptr [[T_ADDR]]
// CHECK: {{%.*}} = call ptr %AssignWithTake(ptr {{.*}} %dest, ptr {{.*}} %src, ptr [[T]])
// ConcreteMoveAsLike initializeWithTake
// CHECK-LABEL: define {{.*}} ptr @"$s10raw_layout18ConcreteMoveAsLikeVwtk"(ptr {{.*}} %dest, ptr {{.*}} %src, ptr %ConcreteMoveAsLike)
// CHECK: [[DEST_CELL:%.*]] = getelementptr inbounds %T10raw_layout18ConcreteMoveAsLikeV, ptr %dest, i32 0, i32 0
// CHECK: [[SRC_CELL:%.*]] = getelementptr inbounds %T10raw_layout18ConcreteMoveAsLikeV, ptr %src, i32 0, i32 0
// CHECK: {{invoke void|invoke ptr|call ptr}} @{{.*}}(ptr [[DEST_CELL]], ptr [[SRC_CELL]])
// ConcreteMoveAsLike assignWithTake
// CHECK-LABEL: define {{.*}} ptr @"$s10raw_layout18ConcreteMoveAsLikeVwta"(ptr {{.*}} %dest, ptr {{.*}} %src, ptr %ConcreteMoveAsLike)
// CHECK: [[DEST_CELL:%.*]] = getelementptr inbounds %T10raw_layout18ConcreteMoveAsLikeV, ptr %dest, i32 0, i32 0
// CHECK: [[SRC_CELL:%.*]] = getelementptr inbounds %T10raw_layout18ConcreteMoveAsLikeV, ptr %src, i32 0, i32 0
// CHECK: {{invoke void|invoke ptr|call ptr}} @{{.*}}(ptr [[DEST_CELL]], ptr [[SRC_CELL]])
|