forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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 llvm#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 llvm#73623. 2. where the aforementioned `InferAlignment` kicks in for overlapping fields (but in this case incorrectly since the structure isn't actually packed).
- Loading branch information
1 parent
e258bb3
commit 2113f05
Showing
4 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
lldb/test/Shell/SymbolFile/DWARF/no_unique_address-alignment.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// XFAIL: * | ||
|
||
// RUN: %clangxx_host -gdwarf -o %t %s | ||
// RUN: %lldb %t \ | ||
// RUN: -o "b main" \ | ||
// 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_packed_struct; | ||
static_assert(alignof(OverlappingFields) == 4); | ||
static_assert(sizeof(OverlappingFields) == 8); | ||
|
||
int main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// RUN: %clangxx_host -gdwarf -o %t %s | ||
// RUN: %lldb %t \ | ||
// RUN: -o "b main" \ | ||
// RUN: -o "expr alignof(packed)" \ | ||
// RUN: -o "expr sizeof(packed)" \ | ||
// RUN: -o "expr alignof(packed_and_aligned)" \ | ||
// RUN: -o "expr sizeof(packed_and_aligned)" \ | ||
// RUN: -o exit | FileCheck %s | ||
|
||
// CHECK: (lldb) expr alignof(packed) | ||
// CHECK-NEXT: ${{.*}} = 1 | ||
// CHECK: (lldb) expr sizeof(packed) | ||
// CHECK-NEXT: ${{.*}} = 9 | ||
|
||
// CHECK: (lldb) expr alignof(packed_and_aligned) | ||
// CHECK-NEXT: ${{.*}} = 16 | ||
// CHECK: (lldb) expr sizeof(packed_and_aligned) | ||
// CHECK-NEXT: ${{.*}} = 16 | ||
|
||
struct __attribute__((packed)) packed { | ||
int x; | ||
char y; | ||
int z; | ||
} g_packed_struct; | ||
static_assert(alignof(packed) == 1); | ||
static_assert(sizeof(packed) == 9); | ||
|
||
struct __attribute__((packed, aligned(16))) packed_and_aligned { | ||
int x; | ||
char y; | ||
int z; | ||
} g_packed_and_aligned_struct; | ||
static_assert(alignof(packed_and_aligned) == 16); | ||
static_assert(sizeof(packed_and_aligned) == 16); | ||
|
||
int main() {} |