@@ -68,26 +68,23 @@ struct __size_difference_type_traits<_Cp, __void_t<typename _Cp::difference_type
68
68
// cast back to the unsigned `_StorageType`.
69
69
70
70
// Creates a mask of type `_StorageType` with a specified number of leading zeros (__clz) and sets all remaining
71
- // bits to one
71
+ // bits to one.
72
72
template <class _StorageType >
73
73
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _StorageType __trailing_mask (unsigned __clz) {
74
74
static_assert (is_unsigned<_StorageType>::value, " __trailing_mask only works with unsigned types" );
75
- return static_cast < _StorageType>( static_cast <_StorageType>(~ static_cast < _StorageType> (0 )) >> __clz) ;
75
+ return _StorageType ( ~ _StorageType (0 )) >> __clz;
76
76
}
77
77
78
78
// Creates a mask of type `_StorageType` with a specified number of leading zeros (__clz), a specified number of
79
- // trailing zeros (__ctz), and sets all bits in between to one
79
+ // trailing zeros (__ctz), and sets all bits in between to one.
80
80
template <class _StorageType >
81
81
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _StorageType __middle_mask (unsigned __clz, unsigned __ctz) {
82
82
static_assert (is_unsigned<_StorageType>::value, " __middle_mask only works with unsigned types" );
83
- return static_cast <_StorageType>(
84
- static_cast <_StorageType>(static_cast <_StorageType>(~static_cast <_StorageType>(0 )) << __ctz) &
85
- std::__trailing_mask<_StorageType>(__clz));
83
+ return _StorageType (_StorageType (~_StorageType (0 )) << __ctz) & std::__trailing_mask<_StorageType>(__clz);
86
84
}
87
85
88
86
// This function is designed to operate correctly even for smaller integral types like `uint8_t`, `uint16_t`,
89
- // or `unsigned short`. Casting back to _StorageType is crucial to prevent undefined behavior that can arise
90
- // from integral promotions.
87
+ // or `unsigned short`.
91
88
// See https://github.com/llvm/llvm-project/pull/122410.
92
89
template <class _StoragePointer >
93
90
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void
@@ -97,8 +94,7 @@ __fill_masked_range(_StoragePointer __word, unsigned __clz, unsigned __ctz, bool
97
94
using _StorageType = typename pointer_traits<_StoragePointer>::element_type;
98
95
_LIBCPP_ASSERT_VALID_INPUT_RANGE (
99
96
__ctz + __clz < sizeof (_StorageType) * CHAR_BIT, " __fill_masked_range called with invalid range" );
100
- _StorageType __m = static_cast <_StorageType>(static_cast <_StorageType>(~static_cast <_StorageType>(0 )) >> __clz) &
101
- static_cast <_StorageType>(static_cast <_StorageType>(~static_cast <_StorageType>(0 )) << __ctz);
97
+ _StorageType __m = std::__middle_mask<_StorageType>(__clz, __ctz);
102
98
if (__fill_val)
103
99
*__word |= __m;
104
100
else
0 commit comments