Skip to content

Commit

Permalink
[libc] fix -Wconversion in float_to_string.h (#74369)
Browse files Browse the repository at this point in the history
Fixes:
libc/src/__support/float_to_string.h:551:48: error: conversion from
‘long
unsigned int’ to ‘int32_t’ {aka ‘int’} may change value
[-Werror=conversion]
551 | const int32_t shift_amount = SHIFT_CONST + (-exponent - IDX_SIZE *
idx);
| ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Observed in gcc fullbuilds.

IDX_SIZE is a size_t (aka 'long unsigned int'), but has the value 128,
so the
expression is undergoing implicit promotion.

Link: https://lab.llvm.org/buildbot/#/builders/250/builds/14891
  • Loading branch information
nickdesaulniers committed Dec 4, 2023
1 parent d1cdcdd commit 0d59cfc
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion libc/src/__support/float_to_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,8 @@ class FloatToString {

val = POW10_SPLIT_2[p];
#endif
const int32_t shift_amount = SHIFT_CONST + (-exponent - IDX_SIZE * idx);
const int32_t shift_amount =
SHIFT_CONST + (-exponent - static_cast<int>(IDX_SIZE) * idx);
uint32_t digits =
internal::mul_shift_mod_1e9(mantissa, val, shift_amount);
return digits;
Expand Down

0 comments on commit 0d59cfc

Please sign in to comment.