Skip to content

Commit f222cd9

Browse files
committed
Reland "[lldb][test] TestDataFormatterLibcxxStringSimulator.py: add new padding layout" (llvm#111123)
Relands llvm#108375 which had to be reverted because it was failing on the Windows buildbot. Trying to reland this with `msvc::no_unique_address` on Windows. (cherry picked from commit d148548)
1 parent afe3708 commit f222cd9

File tree

3 files changed

+52
-23
lines changed

3 files changed

+52
-23
lines changed

lldb/packages/Python/lldbsuite/test/make/libcxx-simulators-common/compressed_pair.h

+23-16
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
namespace std {
88
namespace __lldb {
99

10+
#if __has_cpp_attribute(msvc::no_unique_address)
11+
#define _LLDB_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]]
12+
#elif __has_cpp_attribute(no_unique_address)
13+
#define _LLDB_NO_UNIQUE_ADDRESS [[__no_unique_address__]]
14+
#endif
15+
1016
#if COMPRESSED_PAIR_REV == 0 // Post-c88580c layout
1117
struct __value_init_tag {};
1218
struct __default_init_tag {};
@@ -55,7 +61,7 @@ class __compressed_pair : private __compressed_pair_elem<_T1, 0>,
5561
#elif COMPRESSED_PAIR_REV == 1
5662
// From libc++ datasizeof.h
5763
template <class _Tp> struct _FirstPaddingByte {
58-
[[no_unique_address]] _Tp __v_;
64+
_LLDB_NO_UNIQUE_ADDRESS _Tp __v_;
5965
char __first_padding_byte_;
6066
};
6167

@@ -75,29 +81,30 @@ template <class _ToPad> class __compressed_pair_padding {
7581
};
7682

7783
#define _LLDB_COMPRESSED_PAIR(T1, Initializer1, T2, Initializer2) \
78-
[[__gnu__::__aligned__(alignof(T2))]] [[no_unique_address]] T1 Initializer1; \
79-
[[no_unique_address]] __compressed_pair_padding<T1> __padding1_; \
80-
[[no_unique_address]] T2 Initializer2; \
81-
[[no_unique_address]] __compressed_pair_padding<T2> __padding2_;
84+
[[__gnu__::__aligned__( \
85+
alignof(T2))]] _LLDB_NO_UNIQUE_ADDRESS T1 Initializer1; \
86+
_LLDB_NO_UNIQUE_ADDRESS __compressed_pair_padding<T1> __padding1_; \
87+
_LLDB_NO_UNIQUE_ADDRESS T2 Initializer2; \
88+
_LLDB_NO_UNIQUE_ADDRESS __compressed_pair_padding<T2> __padding2_;
8289

8390
#define _LLDB_COMPRESSED_TRIPLE(T1, Initializer1, T2, Initializer2, T3, \
8491
Initializer3) \
8592
[[using __gnu__: __aligned__(alignof(T2)), \
86-
__aligned__(alignof(T3))]] [[no_unique_address]] T1 Initializer1; \
87-
[[no_unique_address]] __compressed_pair_padding<T1> __padding1_; \
88-
[[no_unique_address]] T2 Initializer2; \
89-
[[no_unique_address]] __compressed_pair_padding<T2> __padding2_; \
90-
[[no_unique_address]] T3 Initializer3; \
91-
[[no_unique_address]] __compressed_pair_padding<T3> __padding3_;
93+
__aligned__(alignof(T3))]] _LLDB_NO_UNIQUE_ADDRESS T1 Initializer1; \
94+
_LLDB_NO_UNIQUE_ADDRESS __compressed_pair_padding<T1> __padding1_; \
95+
_LLDB_NO_UNIQUE_ADDRESS T2 Initializer2; \
96+
_LLDB_NO_UNIQUE_ADDRESS __compressed_pair_padding<T2> __padding2_; \
97+
_LLDB_NO_UNIQUE_ADDRESS T3 Initializer3; \
98+
_LLDB_NO_UNIQUE_ADDRESS __compressed_pair_padding<T3> __padding3_;
9299
#elif COMPRESSED_PAIR_REV == 2
93100
#define _LLDB_COMPRESSED_PAIR(T1, Name1, T2, Name2) \
94-
[[no_unique_address]] T1 Name1; \
95-
[[no_unique_address]] T2 Name2
101+
_LLDB_NO_UNIQUE_ADDRESS T1 Name1; \
102+
_LLDB_NO_UNIQUE_ADDRESS T2 Name2
96103

97104
#define _LLDB_COMPRESSED_TRIPLE(T1, Name1, T2, Name2, T3, Name3) \
98-
[[no_unique_address]] T1 Name1; \
99-
[[no_unique_address]] T2 Name2; \
100-
[[no_unique_address]] T3 Name3
105+
_LLDB_NO_UNIQUE_ADDRESS T1 Name1; \
106+
_LLDB_NO_UNIQUE_ADDRESS T2 Name2; \
107+
_LLDB_NO_UNIQUE_ADDRESS T3 Name3
101108
#endif
102109
} // namespace __lldb
103110
} // namespace std

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+
_LLDB_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+
_LLDB_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)