[libc-commits] [libc] [libc] Make `stdc_first_trailing_one` spec compliant (PR #116493)

via libc-commits libc-commits at lists.llvm.org
Thu Nov 21 16:33:01 PST 2024


================
@@ -146,8 +146,7 @@ first_trailing_zero(T value) {
 template <typename T>
 [[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_unsigned_v<T>, int>
 first_trailing_one(T value) {
-  return value == cpp::numeric_limits<T>::max() ? 0
-                                                : cpp::countr_zero(value) + 1;
+  return value == T(0) ? 0 : cpp::countr_zero(value) + 1;
----------------
strncmp wrote:

So I should just make the change @lntue suggested in `math_extras.h` and if someone wants to port LLVM-libc to some kind of platform, in which `short` has the same width as `int` (so, we'll just have to try to be aware in the future if there is a port to such architecture, it's usually 16-bit MCUs or devices where `CHAR_BIT` is 16, 24 or 32), they can just change it then? Am I getting this right?

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


More information about the libc-commits mailing list