[libcxx-commits] [libcxx] [libc++] Use std::__assume_aligned instead of the builtin in vector (PR #234161)

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Wed Oct 21 04:25:54 PDT 2026


https://github.com/philnik777 updated https://github.com/llvm/llvm-project/pull/234161

>From 3c7d676e247c4e655bc50fd0ff81dad93677fe3c Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Wed, 21 Oct 2026 13:23:50 +0200
Subject: [PATCH] [libc++] Use std::__assume_aligned instead of the builtin in
 vector

---
 libcxx/include/__vector/vector.h | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/libcxx/include/__vector/vector.h b/libcxx/include/__vector/vector.h
index 37a25f20e65cd..e93c0c5f19ea0 100644
--- a/libcxx/include/__vector/vector.h
+++ b/libcxx/include/__vector/vector.h
@@ -35,6 +35,7 @@
 #include <__memory/allocate_at_least.h>
 #include <__memory/allocator.h>
 #include <__memory/allocator_traits.h>
+#include <__memory/assume_aligned.h>
 #include <__memory/compressed_pair.h>
 #include <__memory/noexcept_move_assign_container.h>
 #include <__memory/pointer_traits.h>
@@ -832,10 +833,7 @@ class _LIBCPP_WARN_UNUSED vector {
   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 _Ptr
   __add_alignment_assumption(_Ptr __p) _NOEXCEPT {
-    if (!__libcpp_is_constant_evaluated()) {
-      return static_cast<_Ptr>(__builtin_assume_aligned(__p, _LIBCPP_ALIGNOF(decltype(*__p))));
-    }
-    return __p;
+    return std::__assume_aligned<_LIBCPP_ALIGNOF(decltype(*__p))>(__p);
   }
 
   template <class _Ptr = pointer, __enable_if_t<!is_pointer<_Ptr>::value, int> = 0>



More information about the libcxx-commits mailing list