mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
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
46 lines
715 B
Swift
46 lines
715 B
Swift
// RUN: %empty-directory(%t)
|
|
// RUN: %target-build-swift -module-name=test %s -o %t/a.out
|
|
// RUN: %target-codesign %t/a.out
|
|
// RUN: %target-run %t/a.out | %FileCheck %s
|
|
// RUN: %target-build-swift -module-name=test -O %s -o %t/a.out
|
|
// RUN: %target-codesign %t/a.out
|
|
// RUN: %target-run %t/a.out | %FileCheck %s
|
|
// REQUIRES: executable_test
|
|
|
|
|
|
enum E {
|
|
case A
|
|
}
|
|
|
|
struct X {}
|
|
|
|
struct S {
|
|
let i: Int
|
|
let e: E
|
|
let x: X
|
|
}
|
|
|
|
var gg: Int? = 27
|
|
|
|
@inline(never)
|
|
func getOffsetE() {
|
|
gg = MemoryLayout<S>.offset(of: \.e)
|
|
}
|
|
|
|
@inline(never)
|
|
func getOffsetX() {
|
|
gg = MemoryLayout<S>.offset(of: \.x)
|
|
}
|
|
|
|
getOffsetE()
|
|
|
|
// CHECK: Optional(0)
|
|
print(gg as Any)
|
|
|
|
gg = 27
|
|
|
|
getOffsetX()
|
|
|
|
// CHECK: Optional(0)
|
|
print(gg as Any)
|