Skip to content

[libc][__support] Fix -Wimplicit-int-conversion warning #132839

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 24, 2025

Conversation

ilovepi
Copy link
Contributor

@ilovepi ilovepi commented Mar 24, 2025

Newer versions of clang now warn about these, so use explicit
conversion instead.

Newer versions of clang now warn about these, so use explicit
conversion instead.
Copy link
Contributor Author

ilovepi commented Mar 24, 2025

This stack of pull requests is managed by Graphite. Learn more about stacking.

@ilovepi ilovepi marked this pull request as ready for review March 24, 2025 22:19
@llvmbot llvmbot added the libc label Mar 24, 2025
@llvmbot
Copy link
Member

llvmbot commented Mar 24, 2025

@llvm/pr-subscribers-libc

Author: Paul Kirth (ilovepi)

Changes

Newer versions of clang now warn about these, so use explicit
conversion instead.


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

1 Files Affected:

  • (modified) libc/src/__support/float_to_string.h (+3-3)
diff --git a/libc/src/__support/float_to_string.h b/libc/src/__support/float_to_string.h
index 4b03eaf4d02f2..d88bf844b15af 100644
--- a/libc/src/__support/float_to_string.h
+++ b/libc/src/__support/float_to_string.h
@@ -491,7 +491,7 @@ class FloatToString {
 
   LIBC_INLINE constexpr BlockInt get_negative_block(int block_index) {
     if (exponent < 0) {
-      const int32_t idx = -exponent / IDX_SIZE;
+      const int32_t idx = -exponent / static_cast<int32_t>(IDX_SIZE);
 
       UInt<MID_INT_SIZE> val;
 
@@ -579,7 +579,7 @@ class FloatToString {
 
     return num_requested_digits > -exponent;
 #else
-    const int32_t idx = -exponent / IDX_SIZE;
+    const int32_t idx = -exponent / static_cast<int32_t>(IDX_SIZE);
     const size_t p =
         POW10_OFFSET_2[idx] + negative_block_index - MIN_BLOCK_2[idx];
     // If the remaining digits are all 0, then this is the lowest block.
@@ -601,7 +601,7 @@ class FloatToString {
     }
     return 0;
 #else
-    return MIN_BLOCK_2[-exponent / IDX_SIZE];
+    return MIN_BLOCK_2[-exponent / static_cast<int32_t>(IDX_SIZE)];
 #endif
   }
 };

Copy link
Contributor Author

ilovepi commented Mar 24, 2025

I opted to convert the divisor, since most of the index calculations stored into int32_t. happy to solve this another way if its more appropriate.

Copy link
Contributor Author

ilovepi commented Mar 24, 2025

Merge activity

  • Mar 24, 7:45 PM EDT: A user started a stack merge that includes this pull request via Graphite.
  • Mar 24, 7:47 PM EDT: A user merged this pull request with Graphite.

@ilovepi ilovepi merged commit 0aa4c35 into main Mar 24, 2025
18 of 19 checks passed
@ilovepi ilovepi deleted the users/ilovepi/libc-implicit-cast branch March 24, 2025 23:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants