[libcxx-commits] [libcxx] [libc++] Fix UB in bitwise logic of {std, ranges}::{fill, fill_n} algorithms (PR #122410)
Peng Liu via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Jan 14 20:12:45 PST 2025
================
@@ -56,7 +56,7 @@ __fill_n_bool(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n) {
// do last partial word
if (__n > 0) {
__first.__seg_ += __nw;
- __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
+ __storage_type __m = std::__trailing_mask<__storage_type>(__bits_per_word - __n);
if (_FillVal)
*__first.__seg_ |= __m;
else
----------------
winner245 wrote:
This makes great sense to me. I have introduced `__fill_range_in_word` to set given bit range to a specified value. This also leads to removal of `__trailing_mask`, '__leading_mask', and `__middle_mask.`
https://github.com/llvm/llvm-project/pull/122410
More information about the libcxx-commits
mailing list