Files
swift-mirror/test/IRGen/struct_layout.sil
Erik Eckstein c11408ea2f IRGen: Don't let the offset of an empty field be undef.
If the field address comes from a struct_element_addr which is a result of an optimized `MemoryLayout<S>.offset(of: \.field)` we cannot return undef.
We have to be consistent with `offset(of:)`, which returns 0.
Therefore we need to return the base address of the struct.

rdar://117265274
2024-03-11 15:21:03 +01:00

55 lines
1.4 KiB
Plaintext

// RUN: %target-swift-frontend %s -module-name main -emit-ir -o - | %FileCheck -check-prefix=%target-ptrsize --check-prefix=CHECK %s
import Builtin
import Swift
// 64: %T4main14Rdar15410780_CV = type <{ %TSSSg }>
// 64: %TSSSg = type <{ [16 x i8] }>
// 64: @"$s4main14Rdar15410780_AVWV" = internal constant {{.*}} i64 257
// 64: @"$s4main14Rdar15410780_BVWV" = internal constant {{.*}} i64 258
// 64: @"$s4main14Rdar15410780_CVWV" = internal constant {{.*}} i64 16
// 32: %T4main14Rdar15410780_CV = type <{ %TSSSg }>
// 32: %TSSSg = type <{ [12 x i8] }>
// 32: @"$s4main14Rdar15410780_AVWV" = internal constant {{.*}} i32 257
// 32: @"$s4main14Rdar15410780_BVWV" = internal constant {{.*}} i32 258
// 32: @"$s4main14Rdar15410780_CVWV" = internal constant {{.*}} i32 12
// <rdar://problem/15410780>
struct Rdar15410780_A {
var a: Builtin.Int2048
var b: Int8
}
struct Rdar15410780_B {
var c: Rdar15410780_A?
}
struct Rdar15410780_C {
var d: String?
}
enum EmptyEnum {
case A
}
struct S {
@_hasStorage let x: Int
@_hasStorage let e: EmptyEnum
}
// CHECK-LABEL: define {{.*}} @testOffsetOfEmptyType
// CHECK: ret ptr null
// CHECK: }
sil @testOffsetOfEmptyType : $@convention(thin) () -> Builtin.RawPointer {
bb0:
%0 = base_addr_for_offset $*S
%1 = struct_element_addr %0 : $*S, #S.e
%2 = address_to_pointer %1 : $*EmptyEnum to $Builtin.RawPointer
return %2 : $Builtin.RawPointer
}