[llvm-branch-commits] [libcxx] release/20.x: [libc++] Also provide an alignment assumption for vector in C++03 mode (#124839) (PR #125860)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Feb 5 06:06:59 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libcxx
Author: None (llvmbot)
<details>
<summary>Changes</summary>
Backport ccb08b9
Requested by: @<!-- -->ldionne
---
Full diff: https://github.com/llvm/llvm-project/pull/125860.diff
1 Files Affected:
- (modified) libcxx/include/__vector/vector.h (+11-7)
``````````diff
diff --git a/libcxx/include/__vector/vector.h b/libcxx/include/__vector/vector.h
index 66cb622e2096330..bad676a56a8e643 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, _LIBCPP_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;
}
};
``````````
</details>
https://github.com/llvm/llvm-project/pull/125860
More information about the llvm-branch-commits
mailing list