Files
clang-p2996/lldb/test/Shell/SymbolFile/DWARF/no_unique_address-alignment.cpp
Michael Buch 46e848a23b [lldb][test] Add test-cases for packed/aligned structures (#96932)
Adds test that checks whether LLDB correctly infers the
alignment of packed structures. Specifically, the
`InferAlignment` code-path of the `ItaniumRecordLayoutBuilder`
where it assumes that overlapping field offsets imply a
packed structure and thus sets alignment to `1`. See discussion
in https://github.com/llvm/llvm-project/pull/93809.

While here, also added a test-case where we check alignment of
a class whose base has an explicit `DW_AT_alignment
(those don't get transitively propagated in DWARF, but don't seem
like a problem for LLDB).

Lastly, also added an XFAIL-ed tests where the aforementioned
`InferAlignment` kicks in for overlapping fields (but in this
case incorrectly since the structure isn't actually packed).
2024-06-28 14:15:09 +01:00

25 lines
595 B
C++

// XFAIL: *
// RUN: %clangxx_host -gdwarf -o %t %s
// RUN: %lldb %t \
// RUN: -o "expr alignof(OverlappingFields)" \
// RUN: -o "expr sizeof(OverlappingFields)" \
// RUN: -o exit | FileCheck %s
// CHECK: (lldb) expr alignof(OverlappingFields)
// CHECK-NEXT: ${{.*}} = 4
// CHECK: (lldb) expr sizeof(OverlappingFields)
// CHECK-NEXT: ${{.*}} = 8
struct Empty {};
struct OverlappingFields {
char y;
[[no_unique_address]] Empty e;
int z;
} g_overlapping_struct;
static_assert(alignof(OverlappingFields) == 4);
static_assert(sizeof(OverlappingFields) == 8);
int main() {}