Skip to content

Commit 709c7c2

Browse files
committed
[WIP][lldb][test] Add a new __compressed_pair layout to libcxx simulator tests
1 parent ff7f97a commit 709c7c2

File tree

5 files changed

+81
-24
lines changed

5 files changed

+81
-24
lines changed

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

Lines changed: 33 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,38 @@ 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+
template <class _ToPad> class __compressed_pair_padding {
57+
char __padding_[(is_empty<_ToPad>::value && !__libcpp_is_final<_ToPad>::value)
58+
? 0
59+
: sizeof(_ToPad) - __datasizeof(_ToPad)];
60+
};
61+
62+
#define _LLDB_COMPRESSED_PAIR(T1, Initializer1, T2, Initializer2) \
63+
[[__gnu__::__aligned__(alignof(T2))]] [[no_unique_address]] T1 Initializer1; \
64+
[[no_unique_address]] __compressed_pair_padding<T1> __padding1_; \
65+
[[no_unique_address]] T2 Initializer2; \
66+
[[no_unique_address]] __compressed_pair_padding<T2> __padding2_;
67+
68+
#define _LLDB_COMPRESSED_TRIPLE(T1, Initializer1, T2, Initializer2, T3, \
69+
Initializer3) \
70+
[[using __gnu__: __aligned__(alignof(T2)), \
71+
__aligned__(alignof(T3))]] [[no_unique_address]] T1 Initializer1; \
72+
[[no_unique_address]] __compressed_pair_padding<T1> __padding1_; \
73+
[[no_unique_address]] T2 Initializer2; \
74+
[[no_unique_address]] __compressed_pair_padding<T2> __padding2_; \
75+
[[no_unique_address]] T3 Initializer3; \
76+
[[no_unique_address]] __compressed_pair_padding<T3> __padding3_;
77+
#elif COMPRESSED_PAIR_REV == 2
78+
#define _LLDB_COMPRESSED_PAIR(T1, Name1, T2, Name2) \
79+
[[no_unique_address]] T1 Name1; \
80+
[[no_unique_address]] T2 Name2
81+
82+
#define _LLDB_COMPRESSED_TRIPLE(T1, Name1, T2, Name2, T3, Name3) \
83+
[[no_unique_address]] T1 Name1; \
84+
[[no_unique_address]] T2 Name2; \
85+
[[no_unique_address]] T3 Name3
86+
#endif
5587
} // namespace __lldb
5688
} // namespace std
5789

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
@@ -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

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

186+
#if COMPRESSED_PAIR_REV == 0
186187
std::__lldb::__compressed_pair<__rep, allocator_type> __r_;
188+
#define __R_ __r_
189+
#define __R_L __r_.first().__l
190+
#define __R_S __r_.first().__s
191+
#elif COMPRESSED_PAIR_REV <= 2
192+
_LLDB_COMPRESSED_PAIR(__rep, __rep_, allocator_type, __alloc_);
193+
#define __R_ __rep_
194+
#define __R_L __rep_.__l
195+
#define __R_S __rep_.__s
196+
#endif
187197

188198
public:
189199
template <size_t __N>
190-
basic_string(unsigned char __size, const value_type (&__data)[__N])
191-
: __r_({}, {}) {
200+
basic_string(unsigned char __size, const value_type (&__data)[__N]) {
192201
static_assert(__N < __min_cap, "");
193202
#ifdef BITMASKS
194-
__r_.first().__s.__size_ = __size << __short_shift;
203+
__R_S.__size_ = __size << __short_shift;
195204
#else
196-
__r_.first().__s.__size_ = __size;
197-
__r_.first().__s.__is_long_ = false;
205+
__R_S.__size_ = __size;
206+
__R_S.__is_long_ = false;
198207
#endif
199208
for (size_t __i = 0; __i < __N; ++__i)
200-
__r_.first().__s.__data_[__i] = __data[__i];
209+
__R_S.__data_[__i] = __data[__i];
201210
}
202-
basic_string(size_t __cap, size_type __size, pointer __data) : __r_({}, {}) {
211+
basic_string(size_t __cap, size_type __size, pointer __data) {
203212
#ifdef BITMASKS
204-
__r_.first().__l.__cap_ = __cap | __long_mask;
213+
__R_L.__cap_ = __cap | __long_mask;
205214
#else
206-
__r_.first().__l.__cap_ = __cap / __endian_factor;
207-
__r_.first().__l.__is_long_ = true;
215+
__R_L.__cap_ = __cap / __endian_factor;
216+
__R_L.__is_long_ = true;
208217
#endif
209-
__r_.first().__l.__size_ = __size;
210-
__r_.first().__l.__data_ = __data;
218+
__R_L.__size_ = __size;
219+
__R_L.__data_ = __data;
211220
}
212221
};
213222

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

Lines changed: 12 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,11 @@ def test(self):
2224
self.expect(
2325
"frame variable var_with_deleter_up", substrs=["pointer =", "deleter ="]
2426
)
27+
28+
for r in range(3):
29+
name = "test_r%d" % r
30+
defines = ["COMPRESSED_PAIR_REV=%d" % r]
31+
f = functools.partialmethod(
32+
LibcxxUniquePtrDataFormatterSimulatorTestCase._run_test, defines
33+
)
34+
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)