[libcxx-commits] [libcxx] [libc++] Fix ABI break introduced by switching to _LIBCPP_COMPRESSED_PAIR (PR #154686)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Aug 22 06:27:32 PDT 2025
https://github.com/philnik777 updated https://github.com/llvm/llvm-project/pull/154686
>From b07285ab918aab36e915a35ee17c6a735291af02 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Thu, 21 Aug 2025 09:26:19 +0200
Subject: [PATCH] [libc++] Fix ABI break introduced by switching to
_LIBCPP_COMPRESSED_PAIR
---
libcxx/docs/ReleaseNotes/21.rst | 14 +++++
libcxx/include/__memory/compressed_pair.h | 53 +++++++++++++------
libcxx/include/string | 14 ++++-
.../associative/map/abi.compile.pass.cpp | 4 +-
.../associative/set/abi.compile.pass.cpp | 4 +-
.../unord.map/abi.compile.pass.cpp | 6 +--
.../unord.set/abi.compile.pass.cpp | 6 +--
.../sequences/deque/abi.compile.pass.cpp | 6 +--
.../sequences/list/abi.compile.pass.cpp | 4 +-
.../vector.bool/abi.compile.pass.cpp | 4 +-
.../sequences/vector/abi.compile.pass.cpp | 4 +-
.../unique.ptr.ctor/default.pass.cpp | 4 ++
.../unique.ptr.ctor/nullptr.pass.cpp | 4 ++
.../unique.ptr.ctor/pointer.pass.cpp | 4 ++
14 files changed, 87 insertions(+), 44 deletions(-)
diff --git a/libcxx/docs/ReleaseNotes/21.rst b/libcxx/docs/ReleaseNotes/21.rst
index 91123ffa3e34b..1eaba67b18465 100644
--- a/libcxx/docs/ReleaseNotes/21.rst
+++ b/libcxx/docs/ReleaseNotes/21.rst
@@ -148,6 +148,20 @@ ABI Affecting Changes
comparison between shared libraries, since all RTTI has the correct visibility now. There is no behaviour change on
Clang.
+- LLVM 20 contains an ABI break when
+ (1) using empty allocators which derive from the same base class, or
+ (2) having an object of the same type as an empty member in one of the following classes that could be layed out at
+ the beginnig of the object
+
+ (1) applies to ``unordered_map``, ``unordered_set``, ``unordered_multimap``, ``unordered_multiset`` and ``deque``.
+ (2) applies to the containers listed in (1) as well as ``map``, ``set``, ``multimap``, ``multiset``, ``list`` and
+ ``vector``.
+
+ Fixing this causes a regression in ``unique_ptr``. Specifically, constant evaluation fails when the deleter relies on
+ being value-initialized. If the deleter works if it is default initialized or is not trivially default constructible
+ it is not affected.
+
+ For more details see https://llvm.org/PR154146.
Build System Changes
--------------------
diff --git a/libcxx/include/__memory/compressed_pair.h b/libcxx/include/__memory/compressed_pair.h
index fb7b7b7afcc8c..220dafe856716 100644
--- a/libcxx/include/__memory/compressed_pair.h
+++ b/libcxx/include/__memory/compressed_pair.h
@@ -80,21 +80,44 @@ class __compressed_pair_padding {
template <class _ToPad>
class __compressed_pair_padding<_ToPad, true> {};
-# define _LIBCPP_COMPRESSED_PAIR(T1, Initializer1, T2, Initializer2) \
- _LIBCPP_NO_UNIQUE_ADDRESS __attribute__((__aligned__(::std::__compressed_pair_alignment<T2>))) T1 Initializer1; \
- _LIBCPP_NO_UNIQUE_ADDRESS ::std::__compressed_pair_padding<T1> _LIBCPP_CONCAT3(__padding1_, __LINE__, _); \
- _LIBCPP_NO_UNIQUE_ADDRESS T2 Initializer2; \
- _LIBCPP_NO_UNIQUE_ADDRESS ::std::__compressed_pair_padding<T2> _LIBCPP_CONCAT3(__padding2_, __LINE__, _)
-
-# define _LIBCPP_COMPRESSED_TRIPLE(T1, Initializer1, T2, Initializer2, T3, Initializer3) \
- _LIBCPP_NO_UNIQUE_ADDRESS \
- __attribute__((__aligned__(::std::__compressed_pair_alignment<T2>), \
- __aligned__(::std::__compressed_pair_alignment<T3>))) T1 Initializer1; \
- _LIBCPP_NO_UNIQUE_ADDRESS ::std::__compressed_pair_padding<T1> _LIBCPP_CONCAT3(__padding1_, __LINE__, _); \
- _LIBCPP_NO_UNIQUE_ADDRESS T2 Initializer2; \
- _LIBCPP_NO_UNIQUE_ADDRESS ::std::__compressed_pair_padding<T2> _LIBCPP_CONCAT3(__padding2_, __LINE__, _); \
- _LIBCPP_NO_UNIQUE_ADDRESS T3 Initializer3; \
- _LIBCPP_NO_UNIQUE_ADDRESS ::std::__compressed_pair_padding<T3> _LIBCPP_CONCAT3(__padding3_, __LINE__, _)
+# ifdef _LIBCPP_COMPILER_GCC
+# define _LIBCPP_COMPRESSED_PAIR(T1, Initializer1, T2, Initializer2) \
+ _LIBCPP_NO_UNIQUE_ADDRESS __attribute__((__aligned__(::std::__compressed_pair_alignment<T2>))) T1 Initializer1; \
+ _LIBCPP_NO_UNIQUE_ADDRESS ::std::__compressed_pair_padding<T1> _LIBCPP_CONCAT3(__padding1_, __LINE__, _); \
+ _LIBCPP_NO_UNIQUE_ADDRESS T2 Initializer2; \
+ _LIBCPP_NO_UNIQUE_ADDRESS ::std::__compressed_pair_padding<T2> _LIBCPP_CONCAT3(__padding2_, __LINE__, _)
+
+# define _LIBCPP_COMPRESSED_TRIPLE(T1, Initializer1, T2, Initializer2, T3, Initializer3) \
+ _LIBCPP_NO_UNIQUE_ADDRESS \
+ __attribute__((__aligned__(::std::__compressed_pair_alignment<T2>), \
+ __aligned__(::std::__compressed_pair_alignment<T3>))) T1 Initializer1; \
+ _LIBCPP_NO_UNIQUE_ADDRESS ::std::__compressed_pair_padding<T1> _LIBCPP_CONCAT3(__padding1_, __LINE__, _); \
+ _LIBCPP_NO_UNIQUE_ADDRESS T2 Initializer2; \
+ _LIBCPP_NO_UNIQUE_ADDRESS ::std::__compressed_pair_padding<T2> _LIBCPP_CONCAT3(__padding2_, __LINE__, _); \
+ _LIBCPP_NO_UNIQUE_ADDRESS T3 Initializer3; \
+ _LIBCPP_NO_UNIQUE_ADDRESS ::std::__compressed_pair_padding<T3> _LIBCPP_CONCAT3(__padding3_, __LINE__, _)
+# else
+# define _LIBCPP_COMPRESSED_PAIR(T1, Initializer1, T2, Initializer2) \
+ struct { \
+ _LIBCPP_NO_UNIQUE_ADDRESS \
+ __attribute__((__aligned__(::std::__compressed_pair_alignment<T2>))) T1 Initializer1; \
+ _LIBCPP_NO_UNIQUE_ADDRESS ::std::__compressed_pair_padding<T1> _LIBCPP_CONCAT3(__padding1_, __LINE__, _); \
+ _LIBCPP_NO_UNIQUE_ADDRESS T2 Initializer2; \
+ _LIBCPP_NO_UNIQUE_ADDRESS ::std::__compressed_pair_padding<T2> _LIBCPP_CONCAT3(__padding2_, __LINE__, _); \
+ }
+
+# define _LIBCPP_COMPRESSED_TRIPLE(T1, Initializer1, T2, Initializer2, T3, Initializer3) \
+ struct { \
+ _LIBCPP_NO_UNIQUE_ADDRESS \
+ __attribute__((__aligned__(::std::__compressed_pair_alignment<T2>), \
+ __aligned__(::std::__compressed_pair_alignment<T3>))) T1 Initializer1; \
+ _LIBCPP_NO_UNIQUE_ADDRESS ::std::__compressed_pair_padding<T1> _LIBCPP_CONCAT3(__padding1_, __LINE__, _); \
+ _LIBCPP_NO_UNIQUE_ADDRESS T2 Initializer2; \
+ _LIBCPP_NO_UNIQUE_ADDRESS ::std::__compressed_pair_padding<T2> _LIBCPP_CONCAT3(__padding2_, __LINE__, _); \
+ _LIBCPP_NO_UNIQUE_ADDRESS T3 Initializer3; \
+ _LIBCPP_NO_UNIQUE_ADDRESS ::std::__compressed_pair_padding<T3> _LIBCPP_CONCAT3(__padding3_, __LINE__, _); \
+ }
+# endif
#else
# define _LIBCPP_COMPRESSED_PAIR(T1, Name1, T2, Name2) \
diff --git a/libcxx/include/string b/libcxx/include/string
index 3c1523eb5de33..1d197654b9fee 100644
--- a/libcxx/include/string
+++ b/libcxx/include/string
@@ -974,7 +974,12 @@ public:
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string()
_NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
- : __rep_() {
+# if _LIBCPP_STD_VER >= 20 // TODO(LLVM 23): Remove this condition; this is a workaround for https://llvm.org/PR154567
+ : __rep_(__short())
+# else
+ : __rep_()
+# endif
+ {
__annotate_new(0);
}
@@ -984,7 +989,12 @@ public:
# else
_NOEXCEPT
# endif
- : __rep_(), __alloc_(__a) {
+# if _LIBCPP_STD_VER >= 20 // TODO(LLVM 23): Remove this condition; this is a workaround for https://llvm.org/PR154567
+ : __rep_(__short()),
+# else
+ : __rep_(),
+# endif
+ __alloc_(__a) {
__annotate_new(0);
}
diff --git a/libcxx/test/libcxx/containers/associative/map/abi.compile.pass.cpp b/libcxx/test/libcxx/containers/associative/map/abi.compile.pass.cpp
index 04c1802bc84f6..908338631bb51 100644
--- a/libcxx/test/libcxx/containers/associative/map/abi.compile.pass.cpp
+++ b/libcxx/test/libcxx/containers/associative/map/abi.compile.pass.cpp
@@ -8,8 +8,6 @@
// UNSUPPORTED: libcpp-abi-no-compressed-pair-padding
-// XFAIL: FROZEN-CXX03-HEADERS-FIXME
-
#include <cstdint>
#include <map>
@@ -90,7 +88,7 @@ struct user_struct {
};
#if __SIZE_WIDTH__ == 64
-static_assert(sizeof(user_struct) == 32, "");
+static_assert(sizeof(user_struct) == 24, "");
static_assert(TEST_ALIGNOF(user_struct) == 8, "");
static_assert(sizeof(map_alloc<int, std::allocator<std::pair<const int, int> > >) == 24, "");
diff --git a/libcxx/test/libcxx/containers/associative/set/abi.compile.pass.cpp b/libcxx/test/libcxx/containers/associative/set/abi.compile.pass.cpp
index 1b85bb7c93773..626f573967efb 100644
--- a/libcxx/test/libcxx/containers/associative/set/abi.compile.pass.cpp
+++ b/libcxx/test/libcxx/containers/associative/set/abi.compile.pass.cpp
@@ -8,8 +8,6 @@
// UNSUPPORTED: libcpp-abi-no-compressed-pair-padding
-// XFAIL: FROZEN-CXX03-HEADERS-FIXME
-
#include <cstdint>
#include <set>
@@ -90,7 +88,7 @@ struct user_struct {
};
#if __SIZE_WIDTH__ == 64
-static_assert(sizeof(user_struct) == 32, "");
+static_assert(sizeof(user_struct) == 24, "");
static_assert(TEST_ALIGNOF(user_struct) == 8, "");
static_assert(sizeof(set_alloc<int, std::allocator<int> >) == 24, "");
diff --git a/libcxx/test/libcxx/containers/associative/unord.map/abi.compile.pass.cpp b/libcxx/test/libcxx/containers/associative/unord.map/abi.compile.pass.cpp
index 0476872487036..e6d27d245c472 100644
--- a/libcxx/test/libcxx/containers/associative/unord.map/abi.compile.pass.cpp
+++ b/libcxx/test/libcxx/containers/associative/unord.map/abi.compile.pass.cpp
@@ -12,8 +12,6 @@
// unordered containers changes when bounded unique_ptr is enabled.
// UNSUPPORTED: libcpp-has-abi-bounded-unique_ptr
-// XFAIL: FROZEN-CXX03-HEADERS-FIXME
-
#include <cstdint>
#include <unordered_map>
@@ -94,7 +92,7 @@ struct user_struct {
};
#if __SIZE_WIDTH__ == 64
-static_assert(sizeof(user_struct) == 48, "");
+static_assert(sizeof(user_struct) == 40, "");
static_assert(TEST_ALIGNOF(user_struct) == 8, "");
static_assert(sizeof(unordered_map_alloc<int, std::allocator<std::pair<const int, int> > >) == 40, "");
@@ -126,7 +124,7 @@ struct TEST_ALIGNAS(32) AlignedHash {};
struct UnalignedEqualTo {};
// This part of the ABI has been broken between LLVM 19 and LLVM 20.
-static_assert(sizeof(std::unordered_map<int, int, AlignedHash, UnalignedEqualTo>) == 64, "");
+static_assert(sizeof(std::unordered_map<int, int, AlignedHash, UnalignedEqualTo>) == 96, "");
static_assert(TEST_ALIGNOF(std::unordered_map<int, int, AlignedHash, UnalignedEqualTo>) == 32, "");
#elif __SIZE_WIDTH__ == 32
diff --git a/libcxx/test/libcxx/containers/associative/unord.set/abi.compile.pass.cpp b/libcxx/test/libcxx/containers/associative/unord.set/abi.compile.pass.cpp
index e9d88a126de6c..1658e7e33f850 100644
--- a/libcxx/test/libcxx/containers/associative/unord.set/abi.compile.pass.cpp
+++ b/libcxx/test/libcxx/containers/associative/unord.set/abi.compile.pass.cpp
@@ -12,8 +12,6 @@
// unordered containers changes when bounded unique_ptr is enabled.
// UNSUPPORTED: libcpp-has-abi-bounded-unique_ptr
-// XFAIL: FROZEN-CXX03-HEADERS-FIXME
-
#include <cstdint>
#include <unordered_set>
@@ -94,7 +92,7 @@ struct user_struct {
};
#if __SIZE_WIDTH__ == 64
-static_assert(sizeof(user_struct) == 48, "");
+static_assert(sizeof(user_struct) == 40, "");
static_assert(TEST_ALIGNOF(user_struct) == 8, "");
static_assert(sizeof(unordered_set_alloc<int, std::allocator<int> >) == 40, "");
@@ -125,7 +123,7 @@ struct TEST_ALIGNAS(32) AlignedHash {};
struct UnalignedEqualTo {};
// This part of the ABI has been broken between LLVM 19 and LLVM 20.
-static_assert(sizeof(std::unordered_set<int, AlignedHash, UnalignedEqualTo>) == 64, "");
+static_assert(sizeof(std::unordered_set<int, AlignedHash, UnalignedEqualTo>) == 96, "");
static_assert(TEST_ALIGNOF(std::unordered_set<int, AlignedHash, UnalignedEqualTo>) == 32, "");
#elif __SIZE_WIDTH__ == 32
diff --git a/libcxx/test/libcxx/containers/sequences/deque/abi.compile.pass.cpp b/libcxx/test/libcxx/containers/sequences/deque/abi.compile.pass.cpp
index 38f957f416c87..a19897cbb1588 100644
--- a/libcxx/test/libcxx/containers/sequences/deque/abi.compile.pass.cpp
+++ b/libcxx/test/libcxx/containers/sequences/deque/abi.compile.pass.cpp
@@ -8,8 +8,6 @@
// UNSUPPORTED: libcpp-abi-no-compressed-pair-padding
-// XFAIL: FROZEN-CXX03-HEADERS-FIXME
-
#include <cstdint>
#include <deque>
@@ -88,14 +86,14 @@ static_assert(sizeof(std::deque<int, min_allocator<int> >) == 48, "");
static_assert(sizeof(std::deque<int, test_allocator<int> >) == 80, "");
static_assert(sizeof(std::deque<int, small_iter_allocator<int> >) == 12, "");
static_assert(sizeof(std::deque<int, final_small_iter_allocator<int> >) == 16, "");
-static_assert(sizeof(std::deque<int, common_base_allocator<int> >) == 56, "");
+static_assert(sizeof(std::deque<int, common_base_allocator<int> >) == 48, "");
static_assert(sizeof(std::deque<char>) == 48, "");
static_assert(sizeof(std::deque<char, min_allocator<char> >) == 48, "");
static_assert(sizeof(std::deque<char, test_allocator<char> >) == 80, "");
static_assert(sizeof(std::deque<char, small_iter_allocator<char> >) == 12, "");
static_assert(sizeof(std::deque<char, final_small_iter_allocator<char> >) == 16, "");
-static_assert(sizeof(std::deque<char, common_base_allocator<char> >) == 56, "");
+static_assert(sizeof(std::deque<char, common_base_allocator<char> >) == 48, "");
static_assert(TEST_ALIGNOF(std::deque<int>) == 8, "");
static_assert(TEST_ALIGNOF(std::deque<int, min_allocator<int> >) == 8, "");
diff --git a/libcxx/test/libcxx/containers/sequences/list/abi.compile.pass.cpp b/libcxx/test/libcxx/containers/sequences/list/abi.compile.pass.cpp
index 1737497ab159e..ad10051e514fe 100644
--- a/libcxx/test/libcxx/containers/sequences/list/abi.compile.pass.cpp
+++ b/libcxx/test/libcxx/containers/sequences/list/abi.compile.pass.cpp
@@ -6,8 +6,6 @@
//
//===----------------------------------------------------------------------===//
-// XFAIL: FROZEN-CXX03-HEADERS-FIXME
-
#include <cstdint>
#include <list>
@@ -65,7 +63,7 @@ struct user_struct {
};
#if __SIZE_WIDTH__ == 64
-static_assert(sizeof(user_struct) == 32, "");
+static_assert(sizeof(user_struct) == 24, "");
static_assert(TEST_ALIGNOF(user_struct) == 8, "");
static_assert(sizeof(std::list<int>) == 24, "");
diff --git a/libcxx/test/libcxx/containers/sequences/vector.bool/abi.compile.pass.cpp b/libcxx/test/libcxx/containers/sequences/vector.bool/abi.compile.pass.cpp
index 97e09ab4ca868..109e97a3fe8be 100644
--- a/libcxx/test/libcxx/containers/sequences/vector.bool/abi.compile.pass.cpp
+++ b/libcxx/test/libcxx/containers/sequences/vector.bool/abi.compile.pass.cpp
@@ -8,8 +8,6 @@
// UNSUPPORTED: libcpp-abi-no-compressed-pair-padding
-// XFAIL: FROZEN-CXX03-HEADERS-FIXME
-
#include <cstdint>
#include <vector>
@@ -67,7 +65,7 @@ struct user_struct {
};
#if __SIZE_WIDTH__ == 64
-static_assert(sizeof(user_struct) == 32, "");
+static_assert(sizeof(user_struct) == 24, "");
static_assert(TEST_ALIGNOF(user_struct) == 8, "");
static_assert(sizeof(std::vector<bool>) == 24, "");
diff --git a/libcxx/test/libcxx/containers/sequences/vector/abi.compile.pass.cpp b/libcxx/test/libcxx/containers/sequences/vector/abi.compile.pass.cpp
index 879e143510752..1a55d1359eeb0 100644
--- a/libcxx/test/libcxx/containers/sequences/vector/abi.compile.pass.cpp
+++ b/libcxx/test/libcxx/containers/sequences/vector/abi.compile.pass.cpp
@@ -6,8 +6,6 @@
//
//===----------------------------------------------------------------------===//
-// XFAIL: FROZEN-CXX03-HEADERS-FIXME
-
#include <cstdint>
#include <vector>
@@ -73,7 +71,7 @@ struct user_struct {
};
#if __SIZE_WIDTH__ == 64
-static_assert(sizeof(user_struct) == 32, "");
+static_assert(sizeof(user_struct) == 24, "");
static_assert(TEST_ALIGNOF(user_struct) == 8, "");
static_assert(sizeof(std::vector<int>) == 24, "");
diff --git a/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/default.pass.cpp b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/default.pass.cpp
index 7f4c90922d6c3..e2abfd17d27c3 100644
--- a/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/default.pass.cpp
+++ b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/default.pass.cpp
@@ -82,6 +82,10 @@ TEST_CONSTEXPR_CXX23 bool test_basic() {
p.get_deleter().set_state(5);
assert(p.get_deleter().state() == 5);
}
+// TODO: Remove this check once https://llvm.org/PR154567 is fixed
+#if TEST_STD_VER >= 23 && defined(TEST_COMPILER_CLANG)
+ if (!TEST_IS_CONSTANT_EVALUATED)
+#endif
{
std::unique_ptr<ElemType, DefaultCtorDeleter<ElemType> > p;
assert(p.get() == 0);
diff --git a/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/nullptr.pass.cpp b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/nullptr.pass.cpp
index 45017a03b95dd..f5e0541684d13 100644
--- a/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/nullptr.pass.cpp
+++ b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/nullptr.pass.cpp
@@ -47,6 +47,10 @@ TEST_CONSTEXPR_CXX23 void test_basic() {
assert(p.get() == 0);
assert(p.get_deleter().state() == 0);
}
+// TODO: Remove this check once https://llvm.org/PR154567 is fixed
+#if TEST_STD_VER >= 23 && defined(TEST_COMPILER_CLANG)
+ if (!TEST_IS_CONSTANT_EVALUATED)
+#endif
{
std::unique_ptr<VT, DefaultCtorDeleter<VT> > p(nullptr);
assert(p.get() == 0);
diff --git a/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/pointer.pass.cpp b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/pointer.pass.cpp
index cbce5c9c74c5a..e9912d4574af6 100644
--- a/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/pointer.pass.cpp
+++ b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/pointer.pass.cpp
@@ -75,6 +75,10 @@ TEST_CONSTEXPR_CXX23 void test_pointer() {
}
if (!TEST_IS_CONSTANT_EVALUATED)
assert(A::count == 0);
+// TODO: Remove this check once https://llvm.org/PR154567 is fixed
+#if TEST_STD_VER >= 23 && defined(TEST_COMPILER_CLANG)
+ if (!TEST_IS_CONSTANT_EVALUATED)
+#endif
{
A* p = newValue<ValueT>(expect_alive);
if (!TEST_IS_CONSTANT_EVALUATED)
More information about the libcxx-commits
mailing list