Skip to content

Commit 765e106

Browse files
authored
[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.
1 parent af5a45b commit 765e106

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

Lines changed: 48 additions & 1 deletion
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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@ def _run_test(self, defines):
2828

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

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

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -184,31 +184,50 @@ template <class _CharT, class _Traits, class _Allocator> class basic_string {
184184
};
185185
};
186186

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

189209
public:
190210
template <size_t __N>
191-
basic_string(unsigned char __size, const value_type (&__data)[__N])
192-
: __r_({}, {}) {
211+
basic_string(unsigned char __size, const value_type (&__data)[__N]) {
193212
static_assert(__N < __min_cap, "");
194213
#ifdef BITMASKS
195-
__r_.first().__s.__size_ = __size << __short_shift;
214+
getShortRep().__size_ = __size << __short_shift;
196215
#else
197-
__r_.first().__s.__size_ = __size;
198-
__r_.first().__s.__is_long_ = false;
216+
getShortRep().__size_ = __size;
217+
getShortRep().__is_long_ = false;
199218
#endif
200219
for (size_t __i = 0; __i < __N; ++__i)
201-
__r_.first().__s.__data_[__i] = __data[__i];
220+
getShortRep().__data_[__i] = __data[__i];
202221
}
203-
basic_string(size_t __cap, size_type __size, pointer __data) : __r_({}, {}) {
222+
basic_string(size_t __cap, size_type __size, pointer __data) {
204223
#ifdef BITMASKS
205-
__r_.first().__l.__cap_ = __cap | __long_mask;
224+
getLongRep().__cap_ = __cap | __long_mask;
206225
#else
207-
__r_.first().__l.__cap_ = __cap / __endian_factor;
208-
__r_.first().__l.__is_long_ = true;
226+
getLongRep().__cap_ = __cap / __endian_factor;
227+
getLongRep().__is_long_ = true;
209228
#endif
210-
__r_.first().__l.__size_ = __size;
211-
__r_.first().__l.__data_ = __data;
229+
getLongRep().__size_ = __size;
230+
getLongRep().__data_ = __data;
212231
}
213232
};
214233

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

Lines changed: 13 additions & 2 deletions
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

Lines changed: 5 additions & 0 deletions
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)