Files
clang-p2996/lldb/test/Shell/SymbolFile/DWARF/no_unique_address-base-alignment.cpp
Michael Buch ed9584457d [lldb][test] Add tests for alignof on class with overlapping bases (#97068)
Follow-up to https://github.com/llvm/llvm-project/pull/96932

Adds XFAILed test where LLDB incorrectly infers the alignment of a
derived class whose bases are overlapping due to [[no_unique_address]].
Specifically, the `InferAlignment` code-path of the
`ItaniumRecordLayoutBuilder` assumes that overlapping base offsets imply
a packed structure and thus sets alignment to 1. See discussion in
https://github.com/llvm/llvm-project/pull/93809.

Also adds test where LLDB correctly infers an alignment of `1` when a
packed base class is overlapping with other bases.

Lastly, there were a couple of `alignof` inconsistencies which I
encapsulated in an XFAIL-ed `packed-alignof.cpp`.
2024-06-29 08:38:17 +01:00

31 lines
757 B
C++

// XFAIL: *
// RUN: %clangxx_host -gdwarf -o %t %s
// RUN: %lldb %t \
// RUN: -o "expr alignof(OverlappingDerived)" \
// RUN: -o "expr sizeof(OverlappingDerived)" \
// RUN: -o exit | FileCheck %s
struct Empty {};
struct OverlappingBase {
[[no_unique_address]] Empty e;
};
static_assert(sizeof(OverlappingBase) == 1);
static_assert(alignof(OverlappingBase) == 1);
struct Base {
int mem;
};
struct OverlappingDerived : Base, OverlappingBase {};
static_assert(alignof(OverlappingDerived) == 4);
static_assert(sizeof(OverlappingDerived) == 4);
// CHECK: (lldb) expr alignof(OverlappingDerived)
// CHECK-NEXT: ${{.*}} = 4
// CHECK: (lldb) expr sizeof(OverlappingDerived)
// CHECK-NEXT: ${{.*}} = 4
int main() { OverlappingDerived d; }