Skip to content

Commit 20c2a36

Browse files
committed
[libc++] Replace __compressed_pair with [[no_unique_address]]
1 parent 40a631f commit 20c2a36

File tree

22 files changed

+919
-601
lines changed

22 files changed

+919
-601
lines changed

libcxx/docs/ReleaseNotes/19.rst

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
===========================================
2+
Libc++ 19.0.0 (In-Progress) Release Notes
3+
===========================================
4+
5+
.. contents::
6+
:local:
7+
:depth: 2
8+
9+
Written by the `Libc++ Team <https://libcxx.llvm.org>`_
10+
11+
.. warning::
12+
13+
These are in-progress notes for the upcoming libc++ 18.0.0 release.
14+
Release notes for previous releases can be found on
15+
`the Download Page <https://releases.llvm.org/download.html>`_.
16+
17+
Introduction
18+
============
19+
20+
This document contains the release notes for the libc++ C++ Standard Library,
21+
part of the LLVM Compiler Infrastructure, release 18.0.0. Here we describe the
22+
status of libc++ in some detail, including major improvements from the previous
23+
release and new feature work. For the general LLVM release notes, see `the LLVM
24+
documentation <https://llvm.org/docs/ReleaseNotes.html>`_. All LLVM releases may
25+
be downloaded from the `LLVM releases web site <https://llvm.org/releases/>`_.
26+
27+
For more information about libc++, please see the `Libc++ Web Site
28+
<https://libcxx.llvm.org>`_ or the `LLVM Web Site <https://llvm.org>`_.
29+
30+
Note that if you are reading this file from a Git checkout or the
31+
main Libc++ web page, this document applies to the *next* release, not
32+
the current one. To see the release notes for a specific release, please
33+
see the `releases page <https://llvm.org/releases/>`_.
34+
35+
What's New in Libc++ 18.0.0?
36+
==============================
37+
38+
Implemented Papers
39+
------------------
40+
41+
42+
Improvements and New Features
43+
-----------------------------
44+
45+
- The internal structure ``__compressed_pair`` has been replaced with ``[[no_unique_address]]``, resulting in reduced
46+
compile times and smaller debug information as well as better code gen if optimizations are disabled.
47+
48+
Deprecations and Removals
49+
-------------------------
50+
51+
52+
Upcoming Deprecations and Removals
53+
----------------------------------
54+
55+
LLVM 19
56+
~~~~~~~
57+
58+
- The ``LIBCXX_ENABLE_ASSERTIONS`` CMake variable that was used to enable the safe mode will be deprecated and setting
59+
it will trigger an error; use the ``LIBCXX_HARDENING_MODE`` variable with the value ``extensive`` instead. Similarly,
60+
the ``_LIBCPP_ENABLE_ASSERTIONS`` macro will be deprecated (setting it to ``1`` still enables the extensive mode the
61+
LLVM 19 release while also issuing a deprecation warning). See :ref:`the hardening documentation
62+
<using-hardening-modes>` for more details.
63+
64+
- The base template for ``std::char_traits`` has been marked as deprecated and will be removed in LLVM 19. If you
65+
are using ``std::char_traits`` with types other than ``char``, ``wchar_t``, ``char8_t``, ``char16_t``, ``char32_t``
66+
or a custom character type for which you specialized ``std::char_traits``, your code will stop working when we
67+
remove the base template. The Standard does not mandate that a base template is provided, and such a base template
68+
is bound to be incorrect for some types, which could currently cause unexpected behavior while going undetected.
69+
Note that the ``_LIBCPP_CHAR_TRAITS_REMOVE_BASE_SPECIALIZATION`` macro can be defined in LLVM 18 to eagerly remove
70+
the specialization and prepare code bases for the unconditional removal in LLVM 19.
71+
72+
- The ``_LIBCPP_ENABLE_NARROWING_CONVERSIONS_IN_VARIANT`` macro that changed the behavior for narrowing conversions
73+
in ``std::variant`` will be removed in LLVM 19.
74+
75+
- The ``_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS`` macro has been deprecated in LLVM 18 and will be removed
76+
entirely in LLVM 19.
77+
78+
- The ``_LIBCPP_ENABLE_CXX17_REMOVED_FEATURES`` and
79+
``_LIBCPP_ENABLE_CXX20_REMOVED_FEATURES`` macros have been deprecated
80+
in LLVM 18 and will be removed entirely in LLVM 19.
81+
82+
LLVM 20
83+
~~~~~~~
84+
85+
- The ``LIBCXX_ENABLE_ASSERTIONS`` CMake variable and the ``_LIBCPP_ENABLE_ASSERTIONS`` macro that were used to enable
86+
the safe mode will be removed.
87+
88+
89+
ABI Affecting Changes
90+
---------------------
91+
92+
- The internal structure ``__compressed_pair`` has been replaced with ``[[no_unique_address]]``. This change results in
93+
empty final types to be placed at the beginning of the object instead of where the beginning of the
94+
``__compressed_pair`` subobject was. This is only observable by checking the address of the subobject.
95+
96+
Build System Changes
97+
--------------------

libcxx/include/__config

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@
179179
// pointer from 16 to 8. This changes the output of std::string::max_size,
180180
// which makes it ABI breaking
181181
# define _LIBCPP_ABI_STRING_8_BYTE_ALIGNMENT
182+
// Don't add padding from __compressed_pair
183+
# define _LIBCPP_ABI_NO_COMPRESSED_PAIR_PADDING
182184
# elif _LIBCPP_ABI_VERSION == 1
183185
# if !(defined(_LIBCPP_OBJECT_FORMAT_COFF) || defined(_LIBCPP_OBJECT_FORMAT_XCOFF))
184186
// Enable compiling copies of now inline methods into the dylib to support

libcxx/include/__functional/function.h

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -138,45 +138,46 @@ class __default_alloc_func;
138138

139139
template <class _Fp, class _Ap, class _Rp, class... _ArgTypes>
140140
class __alloc_func<_Fp, _Ap, _Rp(_ArgTypes...)> {
141-
__compressed_pair<_Fp, _Ap> __f_;
141+
_LIBCPP_COMPRESSED_PAIR(_Fp, __func_, _Ap, __alloc_);
142142

143143
public:
144144
typedef _LIBCPP_NODEBUG _Fp _Target;
145145
typedef _LIBCPP_NODEBUG _Ap _Alloc;
146146

147-
_LIBCPP_HIDE_FROM_ABI const _Target& __target() const { return __f_.first(); }
147+
_LIBCPP_HIDE_FROM_ABI const _Target& __target() const { return __func_; }
148148

149149
// WIN32 APIs may define __allocator, so use __get_allocator instead.
150-
_LIBCPP_HIDE_FROM_ABI const _Alloc& __get_allocator() const { return __f_.second(); }
150+
_LIBCPP_HIDE_FROM_ABI const _Alloc& __get_allocator() const { return __alloc_; }
151151

152-
_LIBCPP_HIDE_FROM_ABI explicit __alloc_func(_Target&& __f)
153-
: __f_(piecewise_construct, std::forward_as_tuple(std::move(__f)), std::forward_as_tuple()) {}
152+
_LIBCPP_HIDE_FROM_ABI explicit __alloc_func(_Target&& __f) : __func_(std::move(__f)), __alloc_() {}
154153

155-
_LIBCPP_HIDE_FROM_ABI explicit __alloc_func(const _Target& __f, const _Alloc& __a)
156-
: __f_(piecewise_construct, std::forward_as_tuple(__f), std::forward_as_tuple(__a)) {}
154+
_LIBCPP_HIDE_FROM_ABI explicit __alloc_func(const _Target& __f, const _Alloc& __a) : __func_(__f), __alloc_(__a) {}
157155

158156
_LIBCPP_HIDE_FROM_ABI explicit __alloc_func(const _Target& __f, _Alloc&& __a)
159-
: __f_(piecewise_construct, std::forward_as_tuple(__f), std::forward_as_tuple(std::move(__a))) {}
157+
: __func_(__f), __alloc_(std::move(__a)) {}
160158

161159
_LIBCPP_HIDE_FROM_ABI explicit __alloc_func(_Target&& __f, _Alloc&& __a)
162-
: __f_(piecewise_construct, std::forward_as_tuple(std::move(__f)), std::forward_as_tuple(std::move(__a))) {}
160+
: __func_(std::move(__f)), __alloc_(std::move(__a)) {}
163161

164162
_LIBCPP_HIDE_FROM_ABI _Rp operator()(_ArgTypes&&... __arg) {
165163
typedef __invoke_void_return_wrapper<_Rp> _Invoker;
166-
return _Invoker::__call(__f_.first(), std::forward<_ArgTypes>(__arg)...);
164+
return _Invoker::__call(__func_, std::forward<_ArgTypes>(__arg)...);
167165
}
168166

169167
_LIBCPP_HIDE_FROM_ABI __alloc_func* __clone() const {
170168
typedef allocator_traits<_Alloc> __alloc_traits;
171169
typedef __rebind_alloc<__alloc_traits, __alloc_func> _AA;
172-
_AA __a(__f_.second());
170+
_AA __a(__alloc_);
173171
typedef __allocator_destructor<_AA> _Dp;
174172
unique_ptr<__alloc_func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
175-
::new ((void*)__hold.get()) __alloc_func(__f_.first(), _Alloc(__a));
173+
::new ((void*)__hold.get()) __alloc_func(__func_, _Alloc(__a));
176174
return __hold.release();
177175
}
178176

179-
_LIBCPP_HIDE_FROM_ABI void destroy() _NOEXCEPT { __f_.~__compressed_pair<_Target, _Alloc>(); }
177+
_LIBCPP_HIDE_FROM_ABI void destroy() _NOEXCEPT {
178+
__func_.~_Fp();
179+
__alloc_.~_Alloc();
180+
}
180181

181182
_LIBCPP_HIDE_FROM_ABI static void __destroy_and_delete(__alloc_func* __f) {
182183
typedef allocator_traits<_Alloc> __alloc_traits;

0 commit comments

Comments
 (0)