Skip to content

[lldb][test] Synchronize __compressed_pair_padding with libc++ #142516

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class __compressed_pair : private __compressed_pair_elem<_T1, 0>,

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

// The legacy layout has been patched, see
// https://github.com/llvm/llvm-project/pull/142516.
#if COMPRESSED_PAIR_REV == 1
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>];
};
#else
template <class _ToPad>
inline const bool __is_reference_or_unpadded_object =
(std::is_empty<_ToPad>::value && !__lldb_is_final<_ToPad>::value) ||
sizeof(_ToPad) == __datasizeof_v<_ToPad>;

template <class _Tp>
inline const bool __is_reference_or_unpadded_object<_Tp &> = true;

template <class _Tp>
inline const bool __is_reference_or_unpadded_object<_Tp &&> = true;

template <class _ToPad, bool _Empty = __is_reference_or_unpadded_object<_ToPad>>
class __compressed_pair_padding {
char __padding_[sizeof(_ToPad) - __datasizeof_v<_ToPad>] = {};
};

template <class _ToPad> class __compressed_pair_padding<_ToPad, true> {};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for keeping this in sync! What we would usually do with these simulators is to add the new implementation behind a ifdef COMPRESSED_PAIR_REV == <new version>. To make sure we don't regress users still on the older layout. Do you mind doing that? If it's too finicky I'm happy to give it a shot

Copy link
Contributor Author

@frederick-vs-ja frederick-vs-ja Jun 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for late replying. I'll do this soon I've done this, although this seems unnecessary as there doesn't seem any case where the layout will change.

#endif

#define _LLDB_COMPRESSED_PAIR(T1, Initializer1, T2, Initializer2) \
[[__gnu__::__aligned__( \
Expand All @@ -96,7 +118,7 @@ template <class _ToPad> class __compressed_pair_padding {
_LLDB_NO_UNIQUE_ADDRESS __compressed_pair_padding<T2> __padding2_; \
_LLDB_NO_UNIQUE_ADDRESS T3 Initializer3; \
_LLDB_NO_UNIQUE_ADDRESS __compressed_pair_padding<T3> __padding3_;
#elif COMPRESSED_PAIR_REV == 2
#elif COMPRESSED_PAIR_REV == 3
#define _LLDB_COMPRESSED_PAIR(T1, Name1, T2, Name2) \
_LLDB_NO_UNIQUE_ADDRESS T1 Name1; \
_LLDB_NO_UNIQUE_ADDRESS T2 Name2
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#define COMPRESSED_PAIR_REV 2
#define COMPRESSED_PAIR_REV 3
#include <libcxx-simulators-common/compressed_pair.h>

namespace std {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def _run_test(self, defines):

for v in [None, "ALTERNATE_LAYOUT"]:
for r in range(6):
for c in range(3):
for c in range(4):
name = "test_r%d_c%d" % (r, c)
defines = ["REVISION=%d" % r, "COMPRESSED_PAIR_REV=%d" % c]
if v:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,22 +209,22 @@ template <class _CharT, class _Traits, class _Allocator> class basic_string {
__long &getLongRep() {
#if COMPRESSED_PAIR_REV == 0
return __r_.first().__l;
#elif COMPRESSED_PAIR_REV <= 2
#elif COMPRESSED_PAIR_REV <= 3
return __rep_.__l;
#endif
}

__short &getShortRep() {
#if COMPRESSED_PAIR_REV == 0
return __r_.first().__s;
#elif COMPRESSED_PAIR_REV <= 2
#elif COMPRESSED_PAIR_REV <= 3
return __rep_.__s;
#endif
}

#if COMPRESSED_PAIR_REV == 0
std::__lldb::__compressed_pair<__rep, allocator_type> __r_;
#elif COMPRESSED_PAIR_REV <= 2
#elif COMPRESSED_PAIR_REV <= 3
_LLDB_COMPRESSED_PAIR(__rep, __rep_, allocator_type, __alloc_);
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def _run_test(self, defines):
)


for r in range(3):
for r in range(4):
name = "test_r%d" % r
defines = ["COMPRESSED_PAIR_REV=%d" % r]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ template <class _Tp, class _Dp = default_delete<_Tp>> class unique_ptr {
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
#elif COMPRESSED_PAIR_REV == 1 || COMPRESSED_PAIR_REV == 2 || \
COMPRESSED_PAIR_REV == 3
_LLDB_COMPRESSED_PAIR(pointer, __ptr_, deleter_type, __deleter_);
explicit unique_ptr(pointer __p) noexcept : __ptr_(__p), __deleter_() {}
#endif
Expand Down
Loading