On Sat, 15 Feb 2025, Jonathan Wakely wrote:
> These should have been unsigned, but the static assertions are only in
> the public std::bit_ceil and std::bit_width functions, not the internal
> __bit_ceil and __bit_width ones.
>
> libstdc++-v3/ChangeLog:
>
> * include/experimental/bits/simd.h (__find_next_valid_abi): Cast
> __bit_ceil argument to unsigned.
> * src/c++17/floating_from_chars.cc (__floating_from_chars_hex):
> Cast __bit_ceil argument to unsigned.
> * src/c++17/memory_resource.cc (big_block): Cast __bit_width
> argument to unsigned.
> ---
>
> Tested x86_64-linux.
>
> libstdc++-v3/include/experimental/bits/simd.h | 2 +-
> libstdc++-v3/src/c++17/floating_from_chars.cc | 5 +++--
> libstdc++-v3/src/c++17/memory_resource.cc | 3 ++-
> 3 files changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/libstdc++-v3/include/experimental/bits/simd.h
> b/libstdc++-v3/include/experimental/bits/simd.h
> index 500c1781ae54..f0cb101aaa82 100644
> --- a/libstdc++-v3/include/experimental/bits/simd.h
> +++ b/libstdc++-v3/include/experimental/bits/simd.h
> @@ -4634,7 +4634,7 @@ template <template <int> class _Abi, int _Bytes,
> typename _Tp>
> static constexpr auto
> _S_choose()
> {
> - constexpr int _NextBytes = std::__bit_ceil(_Bytes) / 2;
> + constexpr int _NextBytes = std::__bit_ceil((unsigned)_Bytes) / 2;
> using _NextAbi = _Abi<_NextBytes>;
> if constexpr (_NextBytes < sizeof(_Tp) * 2) // break recursion
> return _Abi<_Bytes>();
> diff --git a/libstdc++-v3/src/c++17/floating_from_chars.cc
> b/libstdc++-v3/src/c++17/floating_from_chars.cc
> index f8b1e23937d2..d48f1c0d4545 100644
> --- a/libstdc++-v3/src/c++17/floating_from_chars.cc
> +++ b/libstdc++-v3/src/c++17/floating_from_chars.cc
> @@ -1102,8 +1102,9 @@ namespace
> {
> // If the leading hexit is not '1', shift MANTISSA to make it so.
> // This normalizes input like "4.08p0" into "1.02p2".
> - const int leading_hexit = mantissa >> mantissa_bits;
> - const int leading_hexit_width = __bit_width(leading_hexit); // FIXME:
> optimize?
> + const unsigned leading_hexit = mantissa >> mantissa_bits;
> + const int leading_hexit_width
> + = __bit_width((unsigned)leading_hexit); // FIXME: optimize?
Not a big deal, but isn't this cast redundant if we've defined
leading_hexit as unsigned?
> __glibcxx_assert(leading_hexit_width >= 1 && leading_hexit_width <= 4);
> shift_mantissa(leading_hexit_width - 1);
> // After this adjustment, we can assume the leading hexit is '1'.
> diff --git a/libstdc++-v3/src/c++17/memory_resource.cc
> b/libstdc++-v3/src/c++17/memory_resource.cc
> index 2b6bfbd4dd33..893736bcf5dd 100644
> --- a/libstdc++-v3/src/c++17/memory_resource.cc
> +++ b/libstdc++-v3/src/c++17/memory_resource.cc
> @@ -588,7 +588,8 @@ namespace pmr
> // The minimum size of a big block.
> // All big_block allocations will be a multiple of this value.
> // Use bit_ceil to get a power of two even for e.g. 20-bit size_t.
> - static constexpr size_t min = __bit_ceil(numeric_limits<size_t>::digits);
> + static constexpr size_t min
> + = __bit_ceil((unsigned)numeric_limits<size_t>::digits);
>
> constexpr
> big_block(size_t bytes, size_t alignment)
> --
> 2.48.1
>
>