Skip to content

Commit 2113f05

Browse files
committed
[lldb][test] Add test-cases for packed structures
Adds test that checks that 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 #93809. Also adds two XFAIL-ed tests: 1. where LLDB doesn't correctly infer the alignment of a derived class whose base has an explicit `DW_AT_alignment. See #73623. 2. where the aforementioned `InferAlignment` kicks in for overlapping fields (but in this case incorrectly since the structure isn't actually packed).
1 parent e258bb3 commit 2113f05

File tree

4 files changed

+75
-0
lines changed

4 files changed

+75
-0
lines changed

lldb/test/API/lang/cpp/alignas_base_class/TestAlignAsBaseClass.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,11 @@ def test(self):
1616
# Verify specified class alignments.
1717
self.expect_expr("alignof(B2)", result_value="8")
1818
self.expect_expr("alignof(EmptyClassAlign8)", result_value="8")
19+
20+
@no_debug_info_test
21+
@expectedFailureAll(bugnumber="https://github.com/llvm/llvm-project/issues/73623")
22+
def test(self):
23+
self.build()
24+
self.dbg.CreateTarget(self.getBuildArtifact("a.out"))
25+
26+
self.expect_expr("alignof(Derived)", result_value="8")

lldb/test/API/lang/cpp/alignas_base_class/main.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,10 @@ D d3g;
1313
struct alignas(8) EmptyClassAlign8 {
1414
} t;
1515

16+
struct alignas(8) __attribute__((packed)) AlignedAndPackedBase {} foo;
17+
18+
struct Derived : AlignedAndPackedBase {
19+
} bar;
20+
static_assert(alignof(Derived) == 8);
21+
1622
int main() {}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// XFAIL: *
2+
3+
// RUN: %clangxx_host -gdwarf -o %t %s
4+
// RUN: %lldb %t \
5+
// RUN: -o "b main" \
6+
// RUN: -o "expr alignof(OverlappingFields)" \
7+
// RUN: -o "expr sizeof(OverlappingFields)" \
8+
// RUN: -o exit | FileCheck %s
9+
10+
// CHECK: (lldb) expr alignof(OverlappingFields)
11+
// CHECK-NEXT: ${{.*}} = 4
12+
// CHECK: (lldb) expr sizeof(OverlappingFields)
13+
// CHECK-NEXT: ${{.*}} = 8
14+
15+
struct Empty {};
16+
17+
struct OverlappingFields {
18+
char y;
19+
[[no_unique_address]] Empty e;
20+
int z;
21+
} g_packed_struct;
22+
static_assert(alignof(OverlappingFields) == 4);
23+
static_assert(sizeof(OverlappingFields) == 8);
24+
25+
int main() {}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// RUN: %clangxx_host -gdwarf -o %t %s
2+
// RUN: %lldb %t \
3+
// RUN: -o "b main" \
4+
// RUN: -o "expr alignof(packed)" \
5+
// RUN: -o "expr sizeof(packed)" \
6+
// RUN: -o "expr alignof(packed_and_aligned)" \
7+
// RUN: -o "expr sizeof(packed_and_aligned)" \
8+
// RUN: -o exit | FileCheck %s
9+
10+
// CHECK: (lldb) expr alignof(packed)
11+
// CHECK-NEXT: ${{.*}} = 1
12+
// CHECK: (lldb) expr sizeof(packed)
13+
// CHECK-NEXT: ${{.*}} = 9
14+
15+
// CHECK: (lldb) expr alignof(packed_and_aligned)
16+
// CHECK-NEXT: ${{.*}} = 16
17+
// CHECK: (lldb) expr sizeof(packed_and_aligned)
18+
// CHECK-NEXT: ${{.*}} = 16
19+
20+
struct __attribute__((packed)) packed {
21+
int x;
22+
char y;
23+
int z;
24+
} g_packed_struct;
25+
static_assert(alignof(packed) == 1);
26+
static_assert(sizeof(packed) == 9);
27+
28+
struct __attribute__((packed, aligned(16))) packed_and_aligned {
29+
int x;
30+
char y;
31+
int z;
32+
} g_packed_and_aligned_struct;
33+
static_assert(alignof(packed_and_aligned) == 16);
34+
static_assert(sizeof(packed_and_aligned) == 16);
35+
36+
int main() {}

0 commit comments

Comments
 (0)