4
4
#include < type_traits>
5
5
#include < utility> // for std::forward
6
6
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
+
7
13
namespace std {
8
14
namespace __lldb {
9
15
@@ -13,7 +19,50 @@ namespace __lldb {
13
19
#define _LLDB_NO_UNIQUE_ADDRESS [[__no_unique_address__]]
14
20
#endif
15
21
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
17
66
struct __value_init_tag {};
18
67
struct __default_init_tag {};
19
68
@@ -59,49 +108,6 @@ class __compressed_pair : private __compressed_pair_elem<_T1, 0>,
59
108
_T1 &first () { return static_cast <_Base1 &>(*this ).__get (); }
60
109
};
61
110
#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
-
105
111
#define _LLDB_COMPRESSED_PAIR (T1, Initializer1, T2, Initializer2 ) \
106
112
[[__gnu__::__aligned__( \
107
113
alignof (T2))]] _LLDB_NO_UNIQUE_ADDRESS T1 Initializer1; \
@@ -127,7 +133,7 @@ template <class _ToPad> class __compressed_pair_padding<_ToPad, true> {};
127
133
_LLDB_NO_UNIQUE_ADDRESS T1 Name1; \
128
134
_LLDB_NO_UNIQUE_ADDRESS T2 Name2; \
129
135
_LLDB_NO_UNIQUE_ADDRESS T3 Name3
130
- #endif
136
+ #endif // COMPRESSED_PAIR_REV == 3
131
137
} // namespace __lldb
132
138
} // namespace std
133
139
0 commit comments