[libc-commits] [libc] 0d59cfc - [libc] fix -Wconversion in float_to_string.h (#74369)
via libc-commits
libc-commits at lists.llvm.org
Mon Dec 4 13:12:55 PST 2023
Author: Nick Desaulniers
Date: 2023-12-04T13:12:51-08:00
New Revision: 0d59cfc7a3446dc6078dfc57783048f490d8d998
URL: https://github.com/llvm/llvm-project/commit/0d59cfc7a3446dc6078dfc57783048f490d8d998
DIFF: https://github.com/llvm/llvm-project/commit/0d59cfc7a3446dc6078dfc57783048f490d8d998.diff
LOG: [libc] fix -Wconversion in float_to_string.h (#74369)
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
Added:
Modified:
libc/src/__support/float_to_string.h
Removed:
################################################################################
diff --git a/libc/src/__support/float_to_string.h b/libc/src/__support/float_to_string.h
index 1bb4e5c5b9246..e198a5a7215fb 100644
--- a/libc/src/__support/float_to_string.h
+++ b/libc/src/__support/float_to_string.h
@@ -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;
More information about the libc-commits
mailing list