Skip to content

Commit 527d386

Browse files
committed
[lldb][test] Add a new __compressed_pair layout to libcxx simulator tests (llvm#99012)
This is a follow-up to llvm#98330 for the upcoming `__compressed_pair` refactor in llvm#93069 This patch just adds the 2 new copies of `_LIBCPP_COMPRESSED_PAIR` layouts to the simulator tests. (cherry picked from commit 765e106)
1 parent 9592a11 commit 527d386

File tree

5 files changed

+107
-24
lines changed

5 files changed

+107
-24
lines changed

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

+48-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
namespace std {
88
namespace __lldb {
99

10-
// Post-c88580c layout
10+
#if COMPRESSED_PAIR_REV == 0 // Post-c88580c layout
1111
struct __value_init_tag {};
1212
struct __default_init_tag {};
1313

@@ -52,6 +52,53 @@ class __compressed_pair : private __compressed_pair_elem<_T1, 0>,
5252

5353
_T1 &first() { return static_cast<_Base1 &>(*this).__get(); }
5454
};
55+
#elif COMPRESSED_PAIR_REV == 1
56+
// From libc++ datasizeof.h
57+
template <class _Tp> struct _FirstPaddingByte {
58+
[[no_unique_address]] _Tp __v_;
59+
char __first_padding_byte_;
60+
};
61+
62+
template <class _Tp>
63+
inline const size_t __datasizeof_v =
64+
__builtin_offsetof(_FirstPaddingByte<_Tp>, __first_padding_byte_);
65+
66+
template <class _Tp>
67+
struct __lldb_is_final : public integral_constant<bool, __is_final(_Tp)> {};
68+
69+
template <class _ToPad> class __compressed_pair_padding {
70+
char __padding_[((is_empty<_ToPad>::value &&
71+
!__lldb_is_final<_ToPad>::value) ||
72+
is_reference<_ToPad>::value)
73+
? 0
74+
: sizeof(_ToPad) - __datasizeof_v<_ToPad>];
75+
};
76+
77+
#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_;
82+
83+
#define _LLDB_COMPRESSED_TRIPLE(T1, Initializer1, T2, Initializer2, T3, \
84+
Initializer3) \
85+
[[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_;
92+
#elif COMPRESSED_PAIR_REV == 2
93+
#define _LLDB_COMPRESSED_PAIR(T1, Name1, T2, Name2) \
94+
[[no_unique_address]] T1 Name1; \
95+
[[no_unique_address]] T2 Name2
96+
97+
#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
101+
#endif
55102
} // namespace __lldb
56103
} // namespace std
57104

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

+10-9
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@ def _run_test(self, defines):
2525

2626
for v in [None, "ALTERNATE_LAYOUT"]:
2727
for r in range(5):
28-
name = "test_r%d" % r
29-
defines = ["REVISION=%d" % r]
30-
if v:
31-
name += "_" + v
32-
defines += [v]
33-
f = functools.partialmethod(
34-
LibcxxStringDataFormatterSimulatorTestCase._run_test, defines
35-
)
36-
setattr(LibcxxStringDataFormatterSimulatorTestCase, name, f)
28+
for c in range(3):
29+
name = "test_r%d_c%d" % (r, c)
30+
defines = ["REVISION=%d" % r, "COMPRESSED_PAIR_REV=%d" % c]
31+
if v:
32+
name += "_" + v
33+
defines += [v]
34+
f = functools.partialmethod(
35+
LibcxxStringDataFormatterSimulatorTestCase._run_test, defines
36+
)
37+
setattr(LibcxxStringDataFormatterSimulatorTestCase, name, f)

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

+31-12
Original file line numberDiff line numberDiff line change
@@ -183,31 +183,50 @@ template <class _CharT, class _Traits, class _Allocator> class basic_string {
183183
};
184184
};
185185

186+
__long &getLongRep() {
187+
#if COMPRESSED_PAIR_REV == 0
188+
return __r_.first().__l;
189+
#elif COMPRESSED_PAIR_REV <= 2
190+
return __rep_.__l;
191+
#endif
192+
}
193+
194+
__short &getShortRep() {
195+
#if COMPRESSED_PAIR_REV == 0
196+
return __r_.first().__s;
197+
#elif COMPRESSED_PAIR_REV <= 2
198+
return __rep_.__s;
199+
#endif
200+
}
201+
202+
#if COMPRESSED_PAIR_REV == 0
186203
std::__lldb::__compressed_pair<__rep, allocator_type> __r_;
204+
#elif COMPRESSED_PAIR_REV <= 2
205+
_LLDB_COMPRESSED_PAIR(__rep, __rep_, allocator_type, __alloc_);
206+
#endif
187207

188208
public:
189209
template <size_t __N>
190-
basic_string(unsigned char __size, const value_type (&__data)[__N])
191-
: __r_({}, {}) {
210+
basic_string(unsigned char __size, const value_type (&__data)[__N]) {
192211
static_assert(__N < __min_cap, "");
193212
#ifdef BITMASKS
194-
__r_.first().__s.__size_ = __size << __short_shift;
213+
getShortRep().__size_ = __size << __short_shift;
195214
#else
196-
__r_.first().__s.__size_ = __size;
197-
__r_.first().__s.__is_long_ = false;
215+
getShortRep().__size_ = __size;
216+
getShortRep().__is_long_ = false;
198217
#endif
199218
for (size_t __i = 0; __i < __N; ++__i)
200-
__r_.first().__s.__data_[__i] = __data[__i];
219+
getShortRep().__data_[__i] = __data[__i];
201220
}
202-
basic_string(size_t __cap, size_type __size, pointer __data) : __r_({}, {}) {
221+
basic_string(size_t __cap, size_type __size, pointer __data) {
203222
#ifdef BITMASKS
204-
__r_.first().__l.__cap_ = __cap | __long_mask;
223+
getLongRep().__cap_ = __cap | __long_mask;
205224
#else
206-
__r_.first().__l.__cap_ = __cap / __endian_factor;
207-
__r_.first().__l.__is_long_ = true;
225+
getLongRep().__cap_ = __cap / __endian_factor;
226+
getLongRep().__is_long_ = true;
208227
#endif
209-
__r_.first().__l.__size_ = __size;
210-
__r_.first().__l.__data_ = __data;
228+
getLongRep().__size_ = __size;
229+
getLongRep().__data_ = __data;
211230
}
212231
};
213232

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

+13-2
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@
77
from lldbsuite.test.decorators import *
88
from lldbsuite.test.lldbtest import *
99
from lldbsuite.test import lldbutil
10+
import functools
1011

1112

1213
class LibcxxUniquePtrDataFormatterSimulatorTestCase(TestBase):
1314
NO_DEBUG_INFO_TESTCASE = True
1415

15-
def test(self):
16-
self.build()
16+
def _run_test(self, defines):
17+
cxxflags_extras = " ".join(["-D%s" % d for d in defines])
18+
self.build(dictionary=dict(CXXFLAGS_EXTRAS=cxxflags_extras))
1719
lldbutil.run_to_source_breakpoint(
1820
self, "Break here", lldb.SBFileSpec("main.cpp")
1921
)
@@ -22,3 +24,12 @@ def test(self):
2224
self.expect(
2325
"frame variable var_with_deleter_up", substrs=["pointer =", "deleter ="]
2426
)
27+
28+
29+
for r in range(3):
30+
name = "test_r%d" % r
31+
defines = ["COMPRESSED_PAIR_REV=%d" % r]
32+
f = functools.partialmethod(
33+
LibcxxUniquePtrDataFormatterSimulatorTestCase._run_test, defines
34+
)
35+
setattr(LibcxxUniquePtrDataFormatterSimulatorTestCase, name, f)

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

+5
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,14 @@ template <class _Tp, class _Dp = default_delete<_Tp>> class unique_ptr {
1616
typedef _Dp deleter_type;
1717
typedef _Tp *pointer;
1818

19+
#if COMPRESSED_PAIR_REV == 0
1920
std::__lldb::__compressed_pair<pointer, deleter_type> __ptr_;
2021
explicit unique_ptr(pointer __p) noexcept
2122
: __ptr_(__p, std::__lldb::__value_init_tag()) {}
23+
#elif COMPRESSED_PAIR_REV == 1 || COMPRESSED_PAIR_REV == 2
24+
_LLDB_COMPRESSED_PAIR(pointer, __ptr_, deleter_type, __deleter_);
25+
explicit unique_ptr(pointer __p) noexcept : __ptr_(__p), __deleter_() {}
26+
#endif
2227
};
2328
} // namespace __lldb
2429
} // namespace std

0 commit comments

Comments
 (0)