Skip to content

Commit 787d514

Browse files
committed
Switch order of __clz and __ctz
1 parent 5f9fa58 commit 787d514

File tree

5 files changed

+20
-10
lines changed

5 files changed

+20
-10
lines changed

libcxx/include/__algorithm/fill_n.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ __fill_n_bool(__bit_iterator<_Cp, false> __first, typename __size_difference_typ
4141
if (__first.__ctz_ != 0) {
4242
__storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_);
4343
__storage_type __dn = std::min(__clz_f, __n);
44-
std::__fill_masked_range(std::__to_address(__first.__seg_), __first.__ctz_, __clz_f - __dn, _FillVal);
44+
std::__fill_masked_range(std::__to_address(__first.__seg_), __clz_f - __dn, __first.__ctz_, _FillVal);
4545
__n -= __dn;
4646
++__first.__seg_;
4747
}
@@ -52,7 +52,7 @@ __fill_n_bool(__bit_iterator<_Cp, false> __first, typename __size_difference_typ
5252
// do last partial word
5353
if (__n > 0) {
5454
__first.__seg_ += __nw;
55-
std::__fill_masked_range(std::__to_address(__first.__seg_), 0u, __bits_per_word - __n, _FillVal);
55+
std::__fill_masked_range(std::__to_address(__first.__seg_), __bits_per_word - __n, 0u, _FillVal);
5656
}
5757
}
5858

libcxx/include/__bit_reference

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,16 @@ struct __size_difference_type_traits<_Cp, __void_t<typename _Cp::difference_type
6262
// This function is designed to operate correctly even for smaller integral types like `uint8_t`, `uint16_t`,
6363
// or `unsigned short`. Casting back to _StorageType is crucial to prevent undefined behavior that can arise
6464
// from integral promotions.
65-
// See https://github.com/llvm/llvm-project/pull/122410
65+
// See https://github.com/llvm/llvm-project/pull/122410.
6666
template <class _StoragePointer,
6767
__enable_if_t<is_unsigned<typename pointer_traits<_StoragePointer>::element_type>::value, int> >
6868
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void
69-
__fill_masked_range(_StoragePointer __word, unsigned __ctz, unsigned __clz, bool __fill_val) {
69+
__fill_masked_range(_StoragePointer __word, unsigned __clz, unsigned __ctz, bool __fill_val) {
7070
using _StorageType = typename pointer_traits<_StoragePointer>::element_type;
7171
_LIBCPP_ASSERT_VALID_INPUT_RANGE(
7272
__ctz + __clz < sizeof(_StorageType) * CHAR_BIT, "__fill_masked_range called with invalid range");
73-
_StorageType __m = static_cast<_StorageType>(static_cast<_StorageType>(~static_cast<_StorageType>(0)) << __ctz) &
74-
static_cast<_StorageType>(static_cast<_StorageType>(~static_cast<_StorageType>(0)) >> __clz);
73+
_StorageType __m = static_cast<_StorageType>(static_cast<_StorageType>(~static_cast<_StorageType>(0)) >> __clz) &
74+
static_cast<_StorageType>(static_cast<_StorageType>(~static_cast<_StorageType>(0)) << __ctz);
7575
if (__fill_val)
7676
*__word |= __m;
7777
else

libcxx/test/std/algorithms/alg.modifying.operations/alg.fill/ranges.fill.pass.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,12 @@ constexpr void test_iterators() {
7878
}
7979
}
8080

81-
// The `ranges::{fill, fill_n}` algorithms require `vector<bool, Alloc>::iterator` to satisfy the
82-
// `std::indirectly_writable` concept when used with `vector<bool, Alloc>`, which is only met since C++23.
81+
// Make sure we behave properly with std::vector<bool> iterators with custom size types, see
82+
// https://github.com/llvm/llvm-project/pull/122410.
83+
//
84+
// The `ranges::{fill, fill_n}` algorithms require `vector<bool, Alloc>::iterator` to satisfy
85+
// the `std::indirectly_writable` concept when used with `vector<bool, Alloc>`, which is only
86+
// satisfied since C++23.
8387
#if TEST_STD_VER >= 23
8488
TEST_CONSTEXPR_CXX20 void test_bititer_with_custom_sized_types() {
8589
{

libcxx/test/std/algorithms/alg.modifying.operations/alg.fill/ranges.fill_n.pass.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,12 @@ constexpr void test_iterators() {
5151
}
5252
}
5353

54-
// The `ranges::{fill, fill_n}` algorithms require `vector<bool, Alloc>::iterator` to satisfy the
55-
// `std::indirectly_writable` concept when used with `vector<bool, Alloc>`, which is only met since C++23.
54+
// Make sure we behave properly with std::vector<bool> iterators with custom size types, see
55+
// https://github.com/llvm/llvm-project/pull/122410.
56+
//
57+
// The `ranges::{fill, fill_n}` algorithms require `vector<bool, Alloc>::iterator` to satisfy
58+
// the `std::indirectly_writable` concept when used with `vector<bool, Alloc>`, which is only
59+
// satisfied since C++23.
5660
#if TEST_STD_VER >= 23
5761
TEST_CONSTEXPR_CXX20 void test_bititer_with_custom_sized_types() {
5862
{

libcxx/test/support/sized_allocator.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
#include "test_macros.h"
1818

19+
// Allocator with a provided size_type and difference_type, used to test corner cases
20+
// like arithmetic on Allocator::size_type in generic code.
1921
template <typename T, typename Size = std::size_t, typename Difference = std::ptrdiff_t>
2022
class sized_allocator {
2123
template <typename U, typename Sz, typename Diff>

0 commit comments

Comments
 (0)