Skip to content

[libc] Fix compilation errors that occur when building with GCC #96976

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion libc/src/__support/FPUtil/NearestIntegerOperations.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ round_using_specific_rounding_mode(T x, int rnd) {
return x;

StorageType trim_value =
bits.get_mantissa() & ((StorageType(1) << trim_size) - 1);
bits.get_mantissa() &
static_cast<StorageType>(((StorageType(1) << trim_size) - 1));
StorageType half_value =
static_cast<StorageType>((StorageType(1) << (trim_size - 1)));
// If exponent is 0, trimSize will be equal to the mantissa width, and
Expand Down
2 changes: 1 addition & 1 deletion libc/src/__support/FPUtil/dyadic_float.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ template <size_t Bits> struct DyadicFloat {
.get_val();
// volatile prevents constant propagation that would result in infinity
// always being returned no matter the current rounding mode.
volatile T two(2.0);
volatile T two = static_cast<T>(2.0);
T r = two * d_hi;

// TODO: Whether rounding down the absolute value to max_normal should
Expand Down
2 changes: 1 addition & 1 deletion libc/src/__support/FPUtil/generic/FMA.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ fma(InType x, InType y, InType z) {
}

DyadicFloat result(prod_sign, prod_lsb_exp - InFPBits::EXP_BIAS, prod_mant);
result.mantissa |= sticky_bits;
result.mantissa |= static_cast<unsigned int>(sticky_bits);
return result.template as<OutType, /*ShouldSignalExceptions=*/true>();
}

Expand Down
7 changes: 3 additions & 4 deletions libc/src/__support/FPUtil/generic/div.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,14 @@ div(InType x, InType y) {

// Number of iterations = full output precision + 1 rounding bit + 1 potential
// leading 0.
constexpr size_t NUM_ITERS = OutFPBits::FRACTION_LEN + 3;
constexpr int NUM_ITERS = OutFPBits::FRACTION_LEN + 3;
int result_exp = xd.exponent - yd.exponent - (NUM_ITERS - 1);

InStorageType q = 0;
InStorageType r = static_cast<InStorageType>(xd.mantissa >> 2);
InStorageType yd_mant_in = static_cast<InStorageType>(yd.mantissa >> 1);

for (size_t i = 0; i < NUM_ITERS; ++i) {
for (int i = 0; i < NUM_ITERS; ++i) {
q <<= 1;
r <<= 1;
if (r >= yd_mant_in) {
Expand All @@ -114,8 +114,7 @@ div(InType x, InType y) {
}

DyadicFloat result(result_sign, result_exp, q);
result.mantissa += r != 0;

result.mantissa |= static_cast<unsigned int>(r != 0);
return result.template as<OutType, /*ShouldSignalExceptions=*/true>();
}

Expand Down
5 changes: 3 additions & 2 deletions libc/src/__support/big_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,8 @@ struct BigInt {
}

// Initialize the first word to |v| and the rest to 0.
template <typename T, typename = cpp::enable_if_t<cpp::is_integral_v<T>>>
template <typename T, typename = cpp::enable_if_t<cpp::is_integral_v<T> &&
!cpp::is_same_v<T, bool>>>
LIBC_INLINE constexpr BigInt(T v) {
constexpr size_t T_SIZE = sizeof(T) * CHAR_BIT;
const bool is_neg = Signed && (v < 0);
Expand Down Expand Up @@ -440,7 +441,7 @@ struct BigInt {
constexpr size_t MAX_COUNT =
T_SIZE > Bits ? WORD_COUNT : T_SIZE / WORD_SIZE;
for (size_t i = 1; i < MAX_COUNT; ++i)
lo += static_cast<T>(val[i]) << (WORD_SIZE * i);
lo += static_cast<T>(static_cast<T>(val[i]) << (WORD_SIZE * i));
if constexpr (Signed && (T_SIZE > Bits)) {
// Extend sign for negative numbers.
constexpr T MASK = (~T(0) << Bits);
Expand Down
Loading