44#include < type_traits>
55#include < utility> // for std::forward
66
7+ // COMPRESSED_PAIR_REV versions:
8+ // 0 -> Post-c88580c layout
9+ // 1 -> Post-27c83382d83dc layout
10+ // 2 -> Post-769c42f4a552a layout
11+ // 3 -> padding-less no_unique_address-based layout (introduced in 27c83382d83dc)
12+
713namespace std {
814namespace __lldb {
915
@@ -13,7 +19,50 @@ namespace __lldb {
1319#define _LLDB_NO_UNIQUE_ADDRESS [[__no_unique_address__]]
1420#endif
1521
16- #if COMPRESSED_PAIR_REV == 0 // Post-c88580c layout
22+ // From libc++ datasizeof.h
23+ template <class _Tp > struct _FirstPaddingByte {
24+ _LLDB_NO_UNIQUE_ADDRESS _Tp __v_;
25+ char __first_padding_byte_;
26+ };
27+
28+ template <class _Tp >
29+ inline const size_t __datasizeof_v =
30+ __builtin_offsetof (_FirstPaddingByte<_Tp>, __first_padding_byte_);
31+
32+ template <class _Tp >
33+ struct __lldb_is_final : public integral_constant <bool , __is_final(_Tp)> {};
34+
35+ // The legacy layout has been patched, see
36+ // https://github.com/llvm/llvm-project/pull/142516.
37+ #if COMPRESSED_PAIR_REV == 1
38+ template <class _ToPad > class __compressed_pair_padding {
39+ char __padding_[((is_empty<_ToPad>::value &&
40+ !__lldb_is_final<_ToPad>::value) ||
41+ is_reference<_ToPad>::value)
42+ ? 0
43+ : sizeof (_ToPad) - __datasizeof_v<_ToPad>];
44+ };
45+ #elif COMPRESSED_PAIR_REV > 1 && COMPRESSED_PAIR_REV < 3
46+ template <class _ToPad >
47+ inline const bool __is_reference_or_unpadded_object =
48+ (std::is_empty<_ToPad>::value && !__lldb_is_final<_ToPad>::value) ||
49+ sizeof (_ToPad) == __datasizeof_v<_ToPad>;
50+
51+ template <class _Tp >
52+ inline const bool __is_reference_or_unpadded_object<_Tp &> = true ;
53+
54+ template <class _Tp >
55+ inline const bool __is_reference_or_unpadded_object<_Tp &&> = true ;
56+
57+ template <class _ToPad , bool _Empty = __is_reference_or_unpadded_object<_ToPad>>
58+ class __compressed_pair_padding {
59+ char __padding_[sizeof (_ToPad) - __datasizeof_v<_ToPad>] = {};
60+ };
61+
62+ template <class _ToPad > class __compressed_pair_padding <_ToPad, true > {};
63+ #endif // COMPRESSED_PAIR_REV == 1
64+
65+ #if COMPRESSED_PAIR_REV == 0
1766struct __value_init_tag {};
1867struct __default_init_tag {};
1968
@@ -59,49 +108,6 @@ class __compressed_pair : private __compressed_pair_elem<_T1, 0>,
59108 _T1 &first () { return static_cast <_Base1 &>(*this ).__get (); }
60109};
61110#elif COMPRESSED_PAIR_REV == 1 || COMPRESSED_PAIR_REV == 2
62- // From libc++ datasizeof.h
63- template <class _Tp > struct _FirstPaddingByte {
64- _LLDB_NO_UNIQUE_ADDRESS _Tp __v_;
65- char __first_padding_byte_;
66- };
67-
68- template <class _Tp >
69- inline const size_t __datasizeof_v =
70- __builtin_offsetof (_FirstPaddingByte<_Tp>, __first_padding_byte_);
71-
72- template <class _Tp >
73- struct __lldb_is_final : public integral_constant <bool , __is_final(_Tp)> {};
74-
75- // The legacy layout has been patched, see
76- // https://github.com/llvm/llvm-project/pull/142516.
77- #if COMPRESSED_PAIR_REV == 1
78- template <class _ToPad > class __compressed_pair_padding {
79- char __padding_[((is_empty<_ToPad>::value &&
80- !__lldb_is_final<_ToPad>::value) ||
81- is_reference<_ToPad>::value)
82- ? 0
83- : sizeof (_ToPad) - __datasizeof_v<_ToPad>];
84- };
85- #else
86- template <class _ToPad >
87- inline const bool __is_reference_or_unpadded_object =
88- (std::is_empty<_ToPad>::value && !__lldb_is_final<_ToPad>::value) ||
89- sizeof (_ToPad) == __datasizeof_v<_ToPad>;
90-
91- template <class _Tp >
92- inline const bool __is_reference_or_unpadded_object<_Tp &> = true ;
93-
94- template <class _Tp >
95- inline const bool __is_reference_or_unpadded_object<_Tp &&> = true ;
96-
97- template <class _ToPad , bool _Empty = __is_reference_or_unpadded_object<_ToPad>>
98- class __compressed_pair_padding {
99- char __padding_[sizeof (_ToPad) - __datasizeof_v<_ToPad>] = {};
100- };
101-
102- template <class _ToPad > class __compressed_pair_padding <_ToPad, true > {};
103- #endif
104-
105111#define _LLDB_COMPRESSED_PAIR (T1, Initializer1, T2, Initializer2 ) \
106112 [[__gnu__::__aligned__( \
107113 alignof (T2))]] _LLDB_NO_UNIQUE_ADDRESS T1 Initializer1; \
@@ -127,7 +133,7 @@ template <class _ToPad> class __compressed_pair_padding<_ToPad, true> {};
127133 _LLDB_NO_UNIQUE_ADDRESS T1 Name1; \
128134 _LLDB_NO_UNIQUE_ADDRESS T2 Name2; \
129135 _LLDB_NO_UNIQUE_ADDRESS T3 Name3
130- #endif
136+ #endif // COMPRESSED_PAIR_REV == 3
131137} // namespace __lldb
132138} // namespace std
133139
0 commit comments