[libcxx-commits] [libcxx] [libc++] Simplify clear_padding.h a bit (PR #212426)
via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Jul 31 04:25:57 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libcxx
Author: Nikolas Klauser (philnik777)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/212426.diff
1 Files Affected:
- (modified) libcxx/include/__atomic/clear_padding.h (+10-23)
``````````diff
diff --git a/libcxx/include/__atomic/clear_padding.h b/libcxx/include/__atomic/clear_padding.h
index 366c7d50b3734..436e06c20c004 100644
--- a/libcxx/include/__atomic/clear_padding.h
+++ b/libcxx/include/__atomic/clear_padding.h
@@ -11,15 +11,10 @@
#include <__config>
#include <__memory/addressof.h>
-#include <__type_traits/conjunction.h>
#include <__type_traits/enable_if.h>
-#include <__type_traits/has_unique_object_representation.h>
-#include <__type_traits/integral_constant.h>
+#include <__type_traits/is_constant_evaluated.h>
#include <__type_traits/is_same.h>
-#include <__type_traits/negation.h>
#include <__type_traits/remove_cv.h>
-#include <__type_traits/remove_cvref.h>
-#include <__utility/forward.h>
#include <cstring>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -31,43 +26,35 @@ _LIBCPP_BEGIN_NAMESPACE_STD
#if __has_builtin(__builtin_clear_padding)
template <class _Tp>
-struct __needs_clear_padding
- : _And<_Not<integral_constant<bool, __has_unique_object_representations(_Tp)> >,
- _Not<is_same<_Tp, float> >,
- _Not<is_same<_Tp, double> > > {};
+inline const bool __needs_clear_padding_v =
+ !__has_unique_object_representations(_Tp) && !is_same<_Tp, float>::value && !is_same<_Tp, double>::value;
-template <class _Tp, __enable_if_t<!__needs_clear_padding<__remove_cvref_t<_Tp> >::value, int> = 0>
+template <class _Tp, __enable_if_t<!__needs_clear_padding_v<__remove_cv_t<_Tp> >, int> = 0>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Tp& __clear_padding_if_needed(_Tp& __obj) _NOEXCEPT {
return __obj;
}
-template <class _Tp, __enable_if_t<__needs_clear_padding<__remove_cvref_t<_Tp> >::value, int> = 0>
+template <class _Tp, __enable_if_t<__needs_clear_padding_v<__remove_cv_t<_Tp> >, int> = 0>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Tp& __clear_padding_if_needed(_Tp& __obj) _NOEXCEPT {
- return __builtin_is_constant_evaluated() ? __obj : (__builtin_clear_padding(std::addressof(__obj)), __obj);
+ return __libcpp_is_constant_evaluated() ? __obj : (__builtin_clear_padding(std::addressof(__obj)), __obj);
}
// clang fails to inline the function when the memory order is a constant
-template <class _Tp,
- class _Up,
- class _CasFunc,
- __enable_if_t<!__needs_clear_padding<__remove_cvref_t<_Tp> >::value, int> = 0>
+template <class _Tp, class _Up, class _CasFunc, __enable_if_t<!__needs_clear_padding_v<__remove_cv_t<_Tp> >, int> = 0>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_ALWAYS_INLINE bool
__atomic_cas_with_clear_padding(_Tp* __expected, _Up __value, _CasFunc&& __cas_func) {
return __cas_func(__expected, __value);
}
-template <class _Tp,
- class _Up,
- class _CasFunc,
- __enable_if_t<__needs_clear_padding<__remove_cvref_t<_Tp> >::value, int> = 0>
+template <class _Tp, class _Up, class _CasFunc, __enable_if_t<__needs_clear_padding_v<__remove_cv_t<_Tp> >, int> = 0>
_LIBCPP_HIDE_FROM_ABI bool __atomic_cas_with_clear_padding(_Tp* __expected, _Up __value, _CasFunc&& __cas_func) {
std::__clear_padding_if_needed(__value);
- __remove_cvref_t<_Tp> __expected_copy = *__expected;
+ __remove_cv_t<_Tp> __expected_copy = *__expected;
std::__clear_padding_if_needed(__expected_copy);
if (__cas_func(std::addressof(__expected_copy), __value)) {
return true;
} else {
- std::memcpy(__expected, std::addressof(__expected_copy), sizeof(__remove_cvref_t<_Tp>));
+ std::memcpy(__expected, std::addressof(__expected_copy), sizeof(__remove_cv_t<_Tp>));
return false;
}
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/212426
More information about the libcxx-commits
mailing list