[libc-commits] [libc] [libc] fix -Wconversion in float_to_string.h (PR #74369)

via libc-commits libc-commits at lists.llvm.org
Mon Dec 4 13:07:17 PST 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: Nick Desaulniers (nickdesaulniers)

<details>
<summary>Changes</summary>

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


---
Full diff: https://github.com/llvm/llvm-project/pull/74369.diff


1 Files Affected:

- (modified) libc/src/__support/float_to_string.h (+1-1) 


``````````diff
diff --git a/libc/src/__support/float_to_string.h b/libc/src/__support/float_to_string.h
index 1bb4e5c5b9246..f1471d0710277 100644
--- a/libc/src/__support/float_to_string.h
+++ b/libc/src/__support/float_to_string.h
@@ -548,7 +548,7 @@ 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;

``````````

</details>


https://github.com/llvm/llvm-project/pull/74369


More information about the libc-commits mailing list