Skip to content

[libc] implicit conversion error on rv32 #138425

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

Closed
mikhailramalho opened this issue May 3, 2025 · 5 comments · Fixed by #138622
Closed

[libc] implicit conversion error on rv32 #138425

mikhailramalho opened this issue May 3, 2025 · 5 comments · Fixed by #138622

Comments

@mikhailramalho
Copy link
Member

Some tests are failing to build on rv32 due to:

/home/mgadelha/tools/llvm-project/libc/src/__support/FPUtil/FPBits.h:760:40: error: implicit conversion loses integer precision: 'int' to 'size_t' (aka 'unsigned int') [-Werror,-Wimplicit-int-conversion]
  760 |       result.set_significand(number >> -ep);
      |                                     ~~ ^~~
/home/mgadelha/tools/llvm-project/libc/src/__support/FPUtil/generic/FMod.h:221:19: note: in instantiation of member function '__llvm_libc_21_0_0_git::fputil::internal::FPRepImpl<__llvm_libc_21_0_0_git::fputil::FPType::IEEE754_Binary128, __llvm_libc_21_0_0_git::fputil::FPBits<long double>>::make_value' requested here
  221 |       return FPB::make_value(d, e_y - 1);
      |                   ^
/home/mgadelha/tools/llvm-project/libc/src/__support/FPUtil/generic/FMod.h:286:18: note: in instantiation of member function '__llvm_libc_21_0_0_git::fputil::generic::FMod<long double>::eval_internal' requested here
  286 |     FPB result = eval_internal(sx, sy);
      |                  ^
/home/mgadelha/tools/llvm-project/libc/src/math/generic/fmodl.cpp:17:46: note: in instantiation of member function '__llvm_libc_21_0_0_git::fputil::generic::FMod<long double>::eval' requested here
   17 |   return fputil::generic::FMod<long double>::eval(x, y);
      |                                              ^
1 error generated.
@llvmbot llvmbot added the libc label May 3, 2025
@llvmbot
Copy link
Member

llvmbot commented May 3, 2025

@llvm/issue-subscribers-libc

Author: Mikhail R. Gadelha (mikhailramalho)

Some tests are failing to build on rv32 due to: ``` /home/mgadelha/tools/llvm-project/libc/src/__support/FPUtil/FPBits.h:760:40: error: implicit conversion loses integer precision: 'int' to 'size_t' (aka 'unsigned int') [-Werror,-Wimplicit-int-conversion] 760 | result.set_significand(number >> -ep); | ~~ ^~~ /home/mgadelha/tools/llvm-project/libc/src/__support/FPUtil/generic/FMod.h:221:19: note: in instantiation of member function '__llvm_libc_21_0_0_git::fputil::internal::FPRepImpl<__llvm_libc_21_0_0_git::fputil::FPType::IEEE754_Binary128, __llvm_libc_21_0_0_git::fputil::FPBits<long double>>::make_value' requested here 221 | return FPB::make_value(d, e_y - 1); | ^ /home/mgadelha/tools/llvm-project/libc/src/__support/FPUtil/generic/FMod.h:286:18: note: in instantiation of member function '__llvm_libc_21_0_0_git::fputil::generic::FMod<long double>::eval_internal' requested here 286 | FPB result = eval_internal(sx, sy); | ^ /home/mgadelha/tools/llvm-project/libc/src/math/generic/fmodl.cpp:17:46: note: in instantiation of member function '__llvm_libc_21_0_0_git::fputil::generic::FMod<long double>::eval' requested here 17 | return fputil::generic::FMod<long double>::eval(x, y); | ^ 1 error generated. ```

@mikhailramalho
Copy link
Member Author

This fixed it for me, but I'm not sure it's the right fix:

diff --git a/libc/src/__support/FPUtil/FPBits.h b/libc/src/__support/FPUtil/FPBits.h
index bee8d0a8dc47..09aaf62bde44 100644
--- a/libc/src/__support/FPUtil/FPBits.h
+++ b/libc/src/__support/FPUtil/FPBits.h
@@ -757,7 +757,7 @@ public:
       result.set_significand(number);
       result.set_biased_exponent(static_cast<StorageType>(ep + 1));
     } else {
-      result.set_significand(number >> -ep);
+      result.set_significand(number >> -static_cast<size_t>(ep));
     }
     return RetT(result.uintval());
   }

@michaelrj-google
Copy link
Contributor

I think the correct fix should have the minus sign inside the cast. To reach this line the value of ep must be negative.

@lntue
Copy link
Contributor

lntue commented May 5, 2025

I think the correct fix should have the minus sign inside the cast. To reach this line the value of ep must be negative.

Yes, the minus sign should be inside the cast. And probably we should use unsigned instead of size_t if it does not cause trouble.

@mikhailramalho
Copy link
Member Author

static_cast(-ep) builds without issue, running the experiments now.

mikhailramalho added a commit to mikhailramalho/llvm-project that referenced this issue May 5, 2025
This patch fixes the following error on rv32 (and possibly other 32-bit
archs):

FPBits.h:760:40: error: implicit conversion loses integer precision: 'int' to 'size_t' (aka 'unsigned int') [-Werror,-Wimplicit-int-conversion]
  760 |       result.set_significand(number >> -ep);

Fixes llvm#138425.
mikhailramalho added a commit that referenced this issue May 6, 2025
This patch fixes the following error on rv32 (and possibly other 32-bit
archs):

FPBits.h:760:40: error: implicit conversion loses integer precision:
'int' to 'size_t' (aka 'unsigned int')
[-Werror,-Wimplicit-int-conversion]
  760 |       result.set_significand(number >> -ep);

Fixes #138425.
GeorgeARM pushed a commit to GeorgeARM/llvm-project that referenced this issue May 7, 2025
This patch fixes the following error on rv32 (and possibly other 32-bit
archs):

FPBits.h:760:40: error: implicit conversion loses integer precision:
'int' to 'size_t' (aka 'unsigned int')
[-Werror,-Wimplicit-int-conversion]
  760 |       result.set_significand(number >> -ep);

Fixes llvm#138425.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants