Skip to content

Commit 119705e

Browse files
[lldb][test] Synchronize __compressed_pair_padding with libc++ (#142516)
This PR mirrors changes of `__compressed_pair_padding` in libc++ into lldb test suite. Related PR for libc++: - #108956 - #109028 - #142125
1 parent d67013a commit 119705e

File tree

6 files changed

+32
-9
lines changed

6 files changed

+32
-9
lines changed

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class __compressed_pair : private __compressed_pair_elem<_T1, 0>,
5858

5959
_T1 &first() { return static_cast<_Base1 &>(*this).__get(); }
6060
};
61-
#elif COMPRESSED_PAIR_REV == 1
61+
#elif COMPRESSED_PAIR_REV == 1 || COMPRESSED_PAIR_REV == 2
6262
// From libc++ datasizeof.h
6363
template <class _Tp> struct _FirstPaddingByte {
6464
_LLDB_NO_UNIQUE_ADDRESS _Tp __v_;
@@ -72,13 +72,35 @@ inline const size_t __datasizeof_v =
7272
template <class _Tp>
7373
struct __lldb_is_final : public integral_constant<bool, __is_final(_Tp)> {};
7474

75+
// The legacy layout has been patched, see
76+
// https://github.com/llvm/llvm-project/pull/142516.
77+
#if COMPRESSED_PAIR_REV == 1
7578
template <class _ToPad> class __compressed_pair_padding {
7679
char __padding_[((is_empty<_ToPad>::value &&
7780
!__lldb_is_final<_ToPad>::value) ||
7881
is_reference<_ToPad>::value)
7982
? 0
8083
: sizeof(_ToPad) - __datasizeof_v<_ToPad>];
8184
};
85+
#else
86+
template <class _ToPad>
87+
inline const bool __is_reference_or_unpadded_object =
88+
(std::is_empty<_ToPad>::value && !__lldb_is_final<_ToPad>::value) ||
89+
sizeof(_ToPad) == __datasizeof_v<_ToPad>;
90+
91+
template <class _Tp>
92+
inline const bool __is_reference_or_unpadded_object<_Tp &> = true;
93+
94+
template <class _Tp>
95+
inline const bool __is_reference_or_unpadded_object<_Tp &&> = true;
96+
97+
template <class _ToPad, bool _Empty = __is_reference_or_unpadded_object<_ToPad>>
98+
class __compressed_pair_padding {
99+
char __padding_[sizeof(_ToPad) - __datasizeof_v<_ToPad>] = {};
100+
};
101+
102+
template <class _ToPad> class __compressed_pair_padding<_ToPad, true> {};
103+
#endif
82104

83105
#define _LLDB_COMPRESSED_PAIR(T1, Initializer1, T2, Initializer2) \
84106
[[__gnu__::__aligned__( \
@@ -96,7 +118,7 @@ template <class _ToPad> class __compressed_pair_padding {
96118
_LLDB_NO_UNIQUE_ADDRESS __compressed_pair_padding<T2> __padding2_; \
97119
_LLDB_NO_UNIQUE_ADDRESS T3 Initializer3; \
98120
_LLDB_NO_UNIQUE_ADDRESS __compressed_pair_padding<T3> __padding3_;
99-
#elif COMPRESSED_PAIR_REV == 2
121+
#elif COMPRESSED_PAIR_REV == 3
100122
#define _LLDB_COMPRESSED_PAIR(T1, Name1, T2, Name2) \
101123
_LLDB_NO_UNIQUE_ADDRESS T1 Name1; \
102124
_LLDB_NO_UNIQUE_ADDRESS T2 Name2

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#define COMPRESSED_PAIR_REV 2
1+
#define COMPRESSED_PAIR_REV 3
22
#include <libcxx-simulators-common/compressed_pair.h>
33

44
namespace std {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def _run_test(self, defines):
2828

2929
for v in [None, "ALTERNATE_LAYOUT"]:
3030
for r in range(6):
31-
for c in range(3):
31+
for c in range(4):
3232
name = "test_r%d_c%d" % (r, c)
3333
defines = ["REVISION=%d" % r, "COMPRESSED_PAIR_REV=%d" % c]
3434
if v:

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,22 +209,22 @@ template <class _CharT, class _Traits, class _Allocator> class basic_string {
209209
__long &getLongRep() {
210210
#if COMPRESSED_PAIR_REV == 0
211211
return __r_.first().__l;
212-
#elif COMPRESSED_PAIR_REV <= 2
212+
#elif COMPRESSED_PAIR_REV <= 3
213213
return __rep_.__l;
214214
#endif
215215
}
216216

217217
__short &getShortRep() {
218218
#if COMPRESSED_PAIR_REV == 0
219219
return __r_.first().__s;
220-
#elif COMPRESSED_PAIR_REV <= 2
220+
#elif COMPRESSED_PAIR_REV <= 3
221221
return __rep_.__s;
222222
#endif
223223
}
224224

225225
#if COMPRESSED_PAIR_REV == 0
226226
std::__lldb::__compressed_pair<__rep, allocator_type> __r_;
227-
#elif COMPRESSED_PAIR_REV <= 2
227+
#elif COMPRESSED_PAIR_REV <= 3
228228
_LLDB_COMPRESSED_PAIR(__rep, __rep_, allocator_type, __alloc_);
229229
#endif
230230

lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx-simulators/unique_ptr/TestDataFormatterLibcxxUniquePtrSimulator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def _run_test(self, defines):
2626
)
2727

2828

29-
for r in range(3):
29+
for r in range(4):
3030
name = "test_r%d" % r
3131
defines = ["COMPRESSED_PAIR_REV=%d" % r]
3232

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ template <class _Tp, class _Dp = default_delete<_Tp>> class unique_ptr {
2020
std::__lldb::__compressed_pair<pointer, deleter_type> __ptr_;
2121
explicit unique_ptr(pointer __p) noexcept
2222
: __ptr_(__p, std::__lldb::__value_init_tag()) {}
23-
#elif COMPRESSED_PAIR_REV == 1 || COMPRESSED_PAIR_REV == 2
23+
#elif COMPRESSED_PAIR_REV == 1 || COMPRESSED_PAIR_REV == 2 || \
24+
COMPRESSED_PAIR_REV == 3
2425
_LLDB_COMPRESSED_PAIR(pointer, __ptr_, deleter_type, __deleter_);
2526
explicit unique_ptr(pointer __p) noexcept : __ptr_(__p), __deleter_() {}
2627
#endif

0 commit comments

Comments
 (0)