Skip to content

Commit d5f6e88

Browse files
authored
[lldb][test] TestDataFormatterLibcxxStringSimulator.py: add new padding layout (#108375)
Depends on #108362 and #108343. Adds new layout for #105865.
1 parent d283705 commit d5f6e88

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx-simulators/string/TestDataFormatterLibcxxStringSimulator.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def _run_test(self, defines):
2727

2828

2929
for v in [None, "ALTERNATE_LAYOUT"]:
30-
for r in range(5):
30+
for r in range(6):
3131
for c in range(3):
3232
name = "test_r%d_c%d" % (r, c)
3333
defines = ["REVISION=%d" % r, "COMPRESSED_PAIR_REV=%d" % c]

lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx-simulators/string/main.cpp

+28-6
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@
2020
// Pre-D128285 layout.
2121
#define PACKED_ANON_STRUCT
2222
#endif
23-
// REVISION == 4: current layout
23+
#if REVISION <= 4
24+
// Pre-2a1ef74 layout.
25+
#define NON_STANDARD_PADDING
26+
#endif
27+
// REVISION == 5: current layout
2428

2529
#ifdef PACKED_ANON_STRUCT
2630
#define BEGIN_PACKED_ANON_STRUCT struct __attribute__((packed)) {
@@ -34,13 +38,21 @@
3438
namespace std {
3539
namespace __lldb {
3640

41+
#ifdef NON_STANDARD_PADDING
3742
#if defined(ALTERNATE_LAYOUT) && defined(SUBCLASS_PADDING)
3843
template <class _CharT, size_t = sizeof(_CharT)> struct __padding {
3944
unsigned char __xx[sizeof(_CharT) - 1];
4045
};
4146

4247
template <class _CharT> struct __padding<_CharT, 1> {};
4348
#endif
49+
#else // !NON_STANDARD_PADDING
50+
template <size_t _PaddingSize> struct __padding {
51+
char __padding_[_PaddingSize];
52+
};
53+
54+
template <> struct __padding<0> {};
55+
#endif
4456

4557
template <class _CharT, class _Traits, class _Allocator> class basic_string {
4658
public:
@@ -77,7 +89,12 @@ template <class _CharT, class _Traits, class _Allocator> class basic_string {
7789
};
7890
#else // !SUBCLASS_PADDING
7991

92+
#ifdef NON_STANDARD_PADDING
8093
unsigned char __padding[sizeof(value_type) - 1];
94+
#else
95+
[[no_unique_address]] __padding<sizeof(value_type) - 1> __padding_;
96+
#endif
97+
8198
#ifdef BITMASKS
8299
unsigned char __size_;
83100
#else // !BITMASKS
@@ -129,21 +146,26 @@ template <class _CharT, class _Traits, class _Allocator> class basic_string {
129146
union {
130147
#ifdef BITMASKS
131148
unsigned char __size_;
132-
#else
149+
#else // !BITMASKS
133150
struct {
134151
unsigned char __is_long_ : 1;
135152
unsigned char __size_ : 7;
136153
};
137-
#endif
154+
#endif // BITMASKS
138155
value_type __lx;
139156
};
140-
#else
157+
#else // !SHORT_UNION
141158
BEGIN_PACKED_ANON_STRUCT
142159
unsigned char __is_long_ : 1;
143160
unsigned char __size_ : 7;
144161
END_PACKED_ANON_STRUCT
145-
char __padding_[sizeof(value_type) - 1];
146-
#endif
162+
#ifdef NON_STANDARD_PADDING
163+
unsigned char __padding[sizeof(value_type) - 1];
164+
#else // !NON_STANDARD_PADDING
165+
[[no_unique_address]] __padding<sizeof(value_type) - 1> __padding_;
166+
#endif // NON_STANDARD_PADDING
167+
168+
#endif // SHORT_UNION
147169
value_type __data_[__min_cap];
148170
};
149171

0 commit comments

Comments
 (0)