[libcxx-commits] [libcxx] [libc++] Use builtin for `std::is_sufficiently_aligned` (PR #173582)

via libcxx-commits libcxx-commits at lists.llvm.org
Thu Dec 25 14:35:40 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libcxx

Author: David Bayer (davebayer)

<details>
<summary>Changes</summary>

This PR makes `std::is_sufficiently_aligned` use clang's `__builtin_is_aligned` builtin if available.

---
Full diff: https://github.com/llvm/llvm-project/pull/173582.diff


1 Files Affected:

- (modified) libcxx/include/__memory/is_sufficiently_aligned.h (+4) 


``````````diff
diff --git a/libcxx/include/__memory/is_sufficiently_aligned.h b/libcxx/include/__memory/is_sufficiently_aligned.h
index 4280920cabb4b..6754a4c17e149 100644
--- a/libcxx/include/__memory/is_sufficiently_aligned.h
+++ b/libcxx/include/__memory/is_sufficiently_aligned.h
@@ -24,7 +24,11 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <size_t _Alignment, class _Tp>
 _LIBCPP_HIDE_FROM_ABI bool is_sufficiently_aligned(_Tp* __ptr) {
+#if __has_builtin(__builtin_is_aligned)
+  return __builtin_is_aligned(__ptr, _Alignment);
+#else
   return reinterpret_cast<uintptr_t>(__ptr) % _Alignment == 0;
+#endif
 }
 
 #endif // _LIBCPP_STD_VER >= 26

``````````

</details>


https://github.com/llvm/llvm-project/pull/173582


More information about the libcxx-commits mailing list