libstdc++: Fix invalid signed arguments to <bit> functions

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.
This commit is contained in:
Jonathan Wakely 2025-02-13 09:40:44 +00:00 committed by Jonathan Wakely
parent 29eb6f8f41
commit 32457bc25f
No known key found for this signature in database
3 changed files with 6 additions and 4 deletions

View file

@ -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>();

View file

@ -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?
__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'.

View file

@ -591,7 +591,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)