Skip to content

Commit 7ef33e6

Browse files
authored
[libc] Fix recently introduced integer-type warnings (llvm#125864)
These warnings all come up in code modified by one of my two recent commits c06d0ff and b53da77, and all relate to implicit integer type conversion. In a build of ours with strict compile options two of them became errors. Even without that problem, it's worth fixing them to reduce noise that might hide a more serious warning.
1 parent d4144ca commit 7ef33e6

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

libc/src/__support/FPUtil/dyadic_float.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ approx_reciprocal(const DyadicFloat<Bits> &a) {
604604
// of correct bits in x' is double the number in x.
605605

606606
// An initial approximation to the reciprocal
607-
DyadicFloat<Bits> x(Sign::POS, -32 - a.exponent - Bits,
607+
DyadicFloat<Bits> x(Sign::POS, -32 - a.exponent - int(Bits),
608608
uint64_t(0xFFFFFFFFFFFFFFFF) /
609609
static_cast<uint64_t>(a.mantissa >> (Bits - 32)));
610610

libc/src/__support/integer_to_string.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ extract_decimal_digit(T &value) {
231231
// Having multiplied it by 6, add the lowest half-word, and then reduce mod
232232
// 10 by normal integer division to finish.
233233
acc_remainder += value.val[0] & HALFWORD_MASK;
234-
uint8_t digit = acc_remainder % 10;
234+
uint8_t digit = static_cast<uint8_t>(acc_remainder % 10);
235235

236236
// Now we have the output digit. Subtract it from the input value, and shift
237237
// right to divide by 2.

libc/src/stdio/printf_core/float_dec_converter_limited.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ struct DigitsOutput {
113113
// enough that for any binary exponent in the range of float128 it will give
114114
// the correct value of floor(log10(2^n)).
115115
LIBC_INLINE int estimate_log10(int exponent_of_2) {
116-
return (exponent_of_2 * 1292913986LL) >> 32;
116+
return static_cast<int>((exponent_of_2 * 1292913986LL) >> 32);
117117
}
118118

119119
// Calculate the actual digits of a decimal representation of an FP number.
@@ -189,7 +189,7 @@ DigitsOutput decimal_digits(DigitsInput input, int precision, bool e_mode) {
189189
// overflow _after_ the multiplication and retry. So if even the smaller
190190
// number of possible output digits is too many, we might as well change our
191191
// mind right now and switch into E mode.
192-
if (log10_input_max - log10_low_digit + 1 > MAX_DIGITS) {
192+
if (log10_input_max - log10_low_digit + 1 > int(MAX_DIGITS)) {
193193
precision = MAX_DIGITS;
194194
e_mode = true;
195195
log10_low_digit = log10_input_min + 1 - precision;
@@ -362,8 +362,8 @@ DigitsOutput decimal_digits(DigitsInput input, int precision, bool e_mode) {
362362
// we made it from and doing the decimal conversion all over again.)
363363
for (size_t i = output.ndigits; i-- > 0;) {
364364
if (output.digits[i] != '9') {
365-
output.digits[i] = internal::int_to_b36_char(
366-
internal::b36_char_to_int(output.digits[i]) + 1);
365+
output.digits[i] = static_cast<char>(internal::int_to_b36_char(
366+
internal::b36_char_to_int(output.digits[i]) + 1));
367367
break;
368368
} else {
369369
output.digits[i] = '0';

0 commit comments

Comments
 (0)