Skip to content

Commit 7a03666

Browse files
authored
[libc] Fix compilation errors that occur when building with GCC (#96976)
1 parent f906e3d commit 7a03666

File tree

5 files changed

+10
-9
lines changed

5 files changed

+10
-9
lines changed

libc/src/__support/FPUtil/NearestIntegerOperations.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,8 @@ round_using_specific_rounding_mode(T x, int rnd) {
199199
return x;
200200

201201
StorageType trim_value =
202-
bits.get_mantissa() & ((StorageType(1) << trim_size) - 1);
202+
bits.get_mantissa() &
203+
static_cast<StorageType>(((StorageType(1) << trim_size) - 1));
203204
StorageType half_value =
204205
static_cast<StorageType>((StorageType(1) << (trim_size - 1)));
205206
// If exponent is 0, trimSize will be equal to the mantissa width, and

libc/src/__support/FPUtil/dyadic_float.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ template <size_t Bits> struct DyadicFloat {
110110
.get_val();
111111
// volatile prevents constant propagation that would result in infinity
112112
// always being returned no matter the current rounding mode.
113-
volatile T two(2.0);
113+
volatile T two = static_cast<T>(2.0);
114114
T r = two * d_hi;
115115

116116
// TODO: Whether rounding down the absolute value to max_normal should

libc/src/__support/FPUtil/generic/FMA.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ fma(InType x, InType y, InType z) {
266266
}
267267

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

libc/src/__support/FPUtil/generic/div.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,14 @@ div(InType x, InType y) {
9797

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

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

107-
for (size_t i = 0; i < NUM_ITERS; ++i) {
107+
for (int i = 0; i < NUM_ITERS; ++i) {
108108
q <<= 1;
109109
r <<= 1;
110110
if (r >= yd_mant_in) {
@@ -114,8 +114,7 @@ div(InType x, InType y) {
114114
}
115115

116116
DyadicFloat result(result_sign, result_exp, q);
117-
result.mantissa += r != 0;
118-
117+
result.mantissa |= static_cast<unsigned int>(r != 0);
119118
return result.template as<OutType, /*ShouldSignalExceptions=*/true>();
120119
}
121120

libc/src/__support/big_int.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,8 @@ struct BigInt {
387387
}
388388

389389
// Initialize the first word to |v| and the rest to 0.
390-
template <typename T, typename = cpp::enable_if_t<cpp::is_integral_v<T>>>
390+
template <typename T, typename = cpp::enable_if_t<cpp::is_integral_v<T> &&
391+
!cpp::is_same_v<T, bool>>>
391392
LIBC_INLINE constexpr BigInt(T v) {
392393
constexpr size_t T_SIZE = sizeof(T) * CHAR_BIT;
393394
const bool is_neg = Signed && (v < 0);
@@ -440,7 +441,7 @@ struct BigInt {
440441
constexpr size_t MAX_COUNT =
441442
T_SIZE > Bits ? WORD_COUNT : T_SIZE / WORD_SIZE;
442443
for (size_t i = 1; i < MAX_COUNT; ++i)
443-
lo += static_cast<T>(val[i]) << (WORD_SIZE * i);
444+
lo += static_cast<T>(static_cast<T>(val[i]) << (WORD_SIZE * i));
444445
if constexpr (Signed && (T_SIZE > Bits)) {
445446
// Extend sign for negative numbers.
446447
constexpr T MASK = (~T(0) << Bits);

0 commit comments

Comments
 (0)