[libcxx-commits] [libcxx] [libc++] Add _LIBCPP_NO_SANITIZE for std::__assume_aligned (PR #220296)
Sharjeel Khan via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Sep 1 10:03:47 PDT 2026
https://github.com/Sharjeel-Khan updated https://github.com/llvm/llvm-project/pull/220296
>From 8e3d8e4544d46287c73b41bf238748e6bb93b015 Mon Sep 17 00:00:00 2001
From: Sharjeel Khan <sharjeelkhan at google.com>
Date: Tue, 1 Sep 2026 09:48:32 -0700
Subject: [PATCH 1/2] [libc++] Add _LIBCPP_NO_SANITIZE for
std::__assume_aligned
std::assume_aligned takes void* from __builtin_assume_aligned and
converts it _Tp* that causes cfi-unrelated-cast to consider it a
downcast leding to CFI checks. Since std::find_if calls
std::assume_aligned on __last, it will lead to CFI check that
dereferences __last causing a failure. Based on discussion, we can just
add _LIBCPP_NO_SANITIZE for cfi-unrelated-cast because it might reject
well-defined behavior.
Fix: https://github.com/llvm/llvm-project/issues/219306
---
libcxx/include/__memory/assume_aligned.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libcxx/include/__memory/assume_aligned.h b/libcxx/include/__memory/assume_aligned.h
index 08f1772cd6dfa..d39d955200271 100644
--- a/libcxx/include/__memory/assume_aligned.h
+++ b/libcxx/include/__memory/assume_aligned.h
@@ -23,7 +23,7 @@
_LIBCPP_BEGIN_NAMESPACE_STD
template <size_t _Np, class _Tp>
-[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp* __assume_aligned(_Tp* __ptr) {
+[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_NO_SANITIZE("cfi-unrelated-cast") _Tp* __assume_aligned(_Tp* __ptr) {
static_assert(_Np != 0 && (_Np & (_Np - 1)) == 0, "std::assume_aligned<N>(p) requires N to be a power of two");
if (__libcpp_is_constant_evaluated()) {
>From f71275085f5c72b9720ff04d507d6cb36effc0d3 Mon Sep 17 00:00:00 2001
From: Sharjeel Khan <sharjeelkhan at google.com>
Date: Tue, 1 Sep 2026 10:03:28 -0700
Subject: [PATCH 2/2] Fix C++ format
---
libcxx/include/__memory/assume_aligned.h | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/libcxx/include/__memory/assume_aligned.h b/libcxx/include/__memory/assume_aligned.h
index d39d955200271..35fa652e203cf 100644
--- a/libcxx/include/__memory/assume_aligned.h
+++ b/libcxx/include/__memory/assume_aligned.h
@@ -23,7 +23,8 @@
_LIBCPP_BEGIN_NAMESPACE_STD
template <size_t _Np, class _Tp>
-[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_NO_SANITIZE("cfi-unrelated-cast") _Tp* __assume_aligned(_Tp* __ptr) {
+[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_NO_SANITIZE("cfi-unrelated-cast") _Tp*
+__assume_aligned(_Tp* __ptr) {
static_assert(_Np != 0 && (_Np & (_Np - 1)) == 0, "std::assume_aligned<N>(p) requires N to be a power of two");
if (__libcpp_is_constant_evaluated()) {
More information about the libcxx-commits
mailing list