[libcxx-commits] [libcxx] [libc++] Also provide an alignment assumption for vector in C++03 mode (PR #124839)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Feb 4 11:48:46 PST 2025
https://github.com/ldionne updated https://github.com/llvm/llvm-project/pull/124839
>From bba08e739257f76cc161fa70eed12001870d2289 Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Tue, 28 Jan 2025 16:11:44 -0500
Subject: [PATCH 1/2] [libc++] Also provide an alignment assumption for vector
in C++03 mode
There's no reason not to, and it's easy enough to do using enable_if.
As a drive-by change, also add a missing _LIBCPP_NO_CFI attribute on
__add_alignment_assumption.
---
libcxx/include/__vector/vector.h | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/libcxx/include/__vector/vector.h b/libcxx/include/__vector/vector.h
index 66cb622e209633..2a79868c94b2cc 100644
--- a/libcxx/include/__vector/vector.h
+++ b/libcxx/include/__vector/vector.h
@@ -783,14 +783,18 @@ class _LIBCPP_TEMPLATE_VIS vector {
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __move_assign_alloc(vector&, false_type) _NOEXCEPT {}
- static _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI pointer __add_alignment_assumption(pointer __p) _NOEXCEPT {
-#ifndef _LIBCPP_CXX03_LANG
- if constexpr (is_pointer<pointer>::value) {
- if (!__libcpp_is_constant_evaluated()) {
- return static_cast<pointer>(__builtin_assume_aligned(__p, alignof(decltype(*__p))));
- }
+ template <class _Ptr = pointer, __enable_if_t<is_pointer<_Ptr>::value, int> = 0>
+ static _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI _LIBCPP_NO_CFI pointer
+ __add_alignment_assumption(_Ptr __p) _NOEXCEPT {
+ if (!__libcpp_is_constant_evaluated()) {
+ return static_cast<pointer>(__builtin_assume_aligned(__p, alignof(decltype(*__p))));
}
-#endif
+ return __p;
+ }
+
+ template <class _Ptr = pointer, __enable_if_t<!is_pointer<_Ptr>::value, int> = 0>
+ static _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI _LIBCPP_NO_CFI pointer
+ __add_alignment_assumption(_Ptr __p) _NOEXCEPT {
return __p;
}
};
>From 1e837266ad4ab7b12c9fbc60d27b776be6dc6fd0 Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Tue, 4 Feb 2025 14:48:21 -0500
Subject: [PATCH 2/2] _LIBCPP_ALIGNOF
---
libcxx/include/__vector/vector.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libcxx/include/__vector/vector.h b/libcxx/include/__vector/vector.h
index 2a79868c94b2cc..bad676a56a8e64 100644
--- a/libcxx/include/__vector/vector.h
+++ b/libcxx/include/__vector/vector.h
@@ -787,7 +787,7 @@ class _LIBCPP_TEMPLATE_VIS vector {
static _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI _LIBCPP_NO_CFI pointer
__add_alignment_assumption(_Ptr __p) _NOEXCEPT {
if (!__libcpp_is_constant_evaluated()) {
- return static_cast<pointer>(__builtin_assume_aligned(__p, alignof(decltype(*__p))));
+ return static_cast<pointer>(__builtin_assume_aligned(__p, _LIBCPP_ALIGNOF(decltype(*__p))));
}
return __p;
}
More information about the libcxx-commits
mailing list