Skip to content

[Libc] Two more implicit to explicit cast changes #130638

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
wants to merge 1 commit into from

Conversation

jplehr
Copy link
Contributor

@jplehr jplehr commented Mar 10, 2025

Those two instances were also flagged with a warning after #126846 landed
and broke the build in two of our bots, e.g., https://lab.llvm.org/buildbot/#/builders/10/builds/1004.

I believe using type T here makes sense, but I can very well be wrong.

Those two instanced were also flagged with a warning after
llvm#126846 landed.

I believe using type T here makes sense, but I can very well be wrong.
@jplehr jplehr requested review from jhuber6 and lntue March 10, 2025 16:49
@llvmbot llvmbot added the libc label Mar 10, 2025
@llvmbot
Copy link
Member

llvmbot commented Mar 10, 2025

@llvm/pr-subscribers-libc

Author: Jan Patrick Lehr (jplehr)

Changes

Those two instances were also flagged with a warning after #126846 landed
and broke the build in two of our bots, e.g., https://lab.llvm.org/buildbot/#/builders/10/builds/1004.

I believe using type T here makes sense, but I can very well be wrong.


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

1 Files Affected:

  • (modified) libc/src/__support/CPP/bit.h (+2-2)
diff --git a/libc/src/__support/CPP/bit.h b/libc/src/__support/CPP/bit.h
index 7d138201783bf..e491f3e032669 100644
--- a/libc/src/__support/CPP/bit.h
+++ b/libc/src/__support/CPP/bit.h
@@ -162,7 +162,7 @@ ADD_SPECIALIZATION(countl_zero, unsigned long long, __builtin_clzll)
 template <typename T>
 [[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_unsigned_v<T>, int>
 countl_one(T value) {
-  return cpp::countl_zero<T>(~value);
+  return cpp::countl_zero<T>(static_cast<T>(~value));
 }
 
 /// Count the number of ones from the least significant bit to the first
@@ -175,7 +175,7 @@ countl_one(T value) {
 template <typename T>
 [[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_unsigned_v<T>, int>
 countr_one(T value) {
-  return cpp::countr_zero<T>(~value);
+  return cpp::countr_zero<T>(static_cast<T>(~value));
 }
 
 /// Returns the number of bits needed to represent value if value is nonzero.

@jplehr
Copy link
Contributor Author

jplehr commented Mar 10, 2025

Diregard in favor of https://github.com/llvm/llvm-project/pull/130635/files

@jplehr jplehr closed this Mar 10, 2025
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.

2 participants