[lldb][test] Add a new __compressed_pair layout to libcxx simulator tests (#99012)

This is a follow-up to https://github.com/llvm/llvm-project/pull/98330
for the upcoming `__compressed_pair` refactor in
https://github.com/llvm/llvm-project/issues/93069

This patch just adds the 2 new copies of `_LIBCPP_COMPRESSED_PAIR`
layouts to the simulator tests.
This commit is contained in:
Michael Buch 2024-09-16 13:46:19 +01:00 committed by GitHub
parent af5a45b34b
commit 765e106fb1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 107 additions and 24 deletions

View File

@ -7,7 +7,7 @@
namespace std {
namespace __lldb {
// Post-c88580c layout
#if COMPRESSED_PAIR_REV == 0 // Post-c88580c layout
struct __value_init_tag {};
struct __default_init_tag {};
@ -52,6 +52,53 @@ public:
_T1 &first() { return static_cast<_Base1 &>(*this).__get(); }
};
#elif COMPRESSED_PAIR_REV == 1
// From libc++ datasizeof.h
template <class _Tp> struct _FirstPaddingByte {
[[no_unique_address]] _Tp __v_;
char __first_padding_byte_;
};
template <class _Tp>
inline const size_t __datasizeof_v =
__builtin_offsetof(_FirstPaddingByte<_Tp>, __first_padding_byte_);
template <class _Tp>
struct __lldb_is_final : public integral_constant<bool, __is_final(_Tp)> {};
template <class _ToPad> class __compressed_pair_padding {
char __padding_[((is_empty<_ToPad>::value &&
!__lldb_is_final<_ToPad>::value) ||
is_reference<_ToPad>::value)
? 0
: sizeof(_ToPad) - __datasizeof_v<_ToPad>];
};
#define _LLDB_COMPRESSED_PAIR(T1, Initializer1, T2, Initializer2) \
[[__gnu__::__aligned__(alignof(T2))]] [[no_unique_address]] T1 Initializer1; \
[[no_unique_address]] __compressed_pair_padding<T1> __padding1_; \
[[no_unique_address]] T2 Initializer2; \
[[no_unique_address]] __compressed_pair_padding<T2> __padding2_;
#define _LLDB_COMPRESSED_TRIPLE(T1, Initializer1, T2, Initializer2, T3, \
Initializer3) \
[[using __gnu__: __aligned__(alignof(T2)), \
__aligned__(alignof(T3))]] [[no_unique_address]] T1 Initializer1; \
[[no_unique_address]] __compressed_pair_padding<T1> __padding1_; \
[[no_unique_address]] T2 Initializer2; \
[[no_unique_address]] __compressed_pair_padding<T2> __padding2_; \
[[no_unique_address]] T3 Initializer3; \
[[no_unique_address]] __compressed_pair_padding<T3> __padding3_;
#elif COMPRESSED_PAIR_REV == 2
#define _LLDB_COMPRESSED_PAIR(T1, Name1, T2, Name2) \
[[no_unique_address]] T1 Name1; \
[[no_unique_address]] T2 Name2
#define _LLDB_COMPRESSED_TRIPLE(T1, Name1, T2, Name2, T3, Name3) \
[[no_unique_address]] T1 Name1; \
[[no_unique_address]] T2 Name2; \
[[no_unique_address]] T3 Name3
#endif
} // namespace __lldb
} // namespace std

View File

@ -28,12 +28,13 @@ class LibcxxStringDataFormatterSimulatorTestCase(TestBase):
for v in [None, "ALTERNATE_LAYOUT"]:
for r in range(5):
name = "test_r%d" % r
defines = ["REVISION=%d" % r]
if v:
name += "_" + v
defines += [v]
f = functools.partialmethod(
LibcxxStringDataFormatterSimulatorTestCase._run_test, defines
)
setattr(LibcxxStringDataFormatterSimulatorTestCase, name, f)
for c in range(3):
name = "test_r%d_c%d" % (r, c)
defines = ["REVISION=%d" % r, "COMPRESSED_PAIR_REV=%d" % c]
if v:
name += "_" + v
defines += [v]
f = functools.partialmethod(
LibcxxStringDataFormatterSimulatorTestCase._run_test, defines
)
setattr(LibcxxStringDataFormatterSimulatorTestCase, name, f)

View File

@ -184,31 +184,50 @@ public:
};
};
__long &getLongRep() {
#if COMPRESSED_PAIR_REV == 0
return __r_.first().__l;
#elif COMPRESSED_PAIR_REV <= 2
return __rep_.__l;
#endif
}
__short &getShortRep() {
#if COMPRESSED_PAIR_REV == 0
return __r_.first().__s;
#elif COMPRESSED_PAIR_REV <= 2
return __rep_.__s;
#endif
}
#if COMPRESSED_PAIR_REV == 0
std::__lldb::__compressed_pair<__rep, allocator_type> __r_;
#elif COMPRESSED_PAIR_REV <= 2
_LLDB_COMPRESSED_PAIR(__rep, __rep_, allocator_type, __alloc_);
#endif
public:
template <size_t __N>
basic_string(unsigned char __size, const value_type (&__data)[__N])
: __r_({}, {}) {
basic_string(unsigned char __size, const value_type (&__data)[__N]) {
static_assert(__N < __min_cap, "");
#ifdef BITMASKS
__r_.first().__s.__size_ = __size << __short_shift;
getShortRep().__size_ = __size << __short_shift;
#else
__r_.first().__s.__size_ = __size;
__r_.first().__s.__is_long_ = false;
getShortRep().__size_ = __size;
getShortRep().__is_long_ = false;
#endif
for (size_t __i = 0; __i < __N; ++__i)
__r_.first().__s.__data_[__i] = __data[__i];
getShortRep().__data_[__i] = __data[__i];
}
basic_string(size_t __cap, size_type __size, pointer __data) : __r_({}, {}) {
basic_string(size_t __cap, size_type __size, pointer __data) {
#ifdef BITMASKS
__r_.first().__l.__cap_ = __cap | __long_mask;
getLongRep().__cap_ = __cap | __long_mask;
#else
__r_.first().__l.__cap_ = __cap / __endian_factor;
__r_.first().__l.__is_long_ = true;
getLongRep().__cap_ = __cap / __endian_factor;
getLongRep().__is_long_ = true;
#endif
__r_.first().__l.__size_ = __size;
__r_.first().__l.__data_ = __data;
getLongRep().__size_ = __size;
getLongRep().__data_ = __data;
}
};

View File

@ -7,13 +7,15 @@ import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
import functools
class LibcxxUniquePtrDataFormatterSimulatorTestCase(TestBase):
NO_DEBUG_INFO_TESTCASE = True
def test(self):
self.build()
def _run_test(self, defines):
cxxflags_extras = " ".join(["-D%s" % d for d in defines])
self.build(dictionary=dict(CXXFLAGS_EXTRAS=cxxflags_extras))
lldbutil.run_to_source_breakpoint(
self, "Break here", lldb.SBFileSpec("main.cpp")
)
@ -22,3 +24,12 @@ class LibcxxUniquePtrDataFormatterSimulatorTestCase(TestBase):
self.expect(
"frame variable var_with_deleter_up", substrs=["pointer =", "deleter ="]
)
for r in range(3):
name = "test_r%d" % r
defines = ["COMPRESSED_PAIR_REV=%d" % r]
f = functools.partialmethod(
LibcxxUniquePtrDataFormatterSimulatorTestCase._run_test, defines
)
setattr(LibcxxUniquePtrDataFormatterSimulatorTestCase, name, f)

View File

@ -16,9 +16,14 @@ public:
typedef _Dp deleter_type;
typedef _Tp *pointer;
#if COMPRESSED_PAIR_REV == 0
std::__lldb::__compressed_pair<pointer, deleter_type> __ptr_;
explicit unique_ptr(pointer __p) noexcept
: __ptr_(__p, std::__lldb::__value_init_tag()) {}
#elif COMPRESSED_PAIR_REV == 1 || COMPRESSED_PAIR_REV == 2
_LLDB_COMPRESSED_PAIR(pointer, __ptr_, deleter_type, __deleter_);
explicit unique_ptr(pointer __p) noexcept : __ptr_(__p), __deleter_() {}
#endif
};
} // namespace __lldb
} // namespace std