Re: [PATCH v1 3/5] bitops: Silence a clang -Wshorten-64-to-32 warning
From: Arnd Bergmann
Date: Fri Apr 04 2025 - 01:43:35 EST
On Thu, Apr 3, 2025, at 18:57, Ian Rogers wrote:
> The clang warning -Wshorten-64-to-32 can be useful to catch
> inadvertent truncation. In some instances this truncation can lead to
> changing the sign of a result, for example, truncation to return an
> int to fit a sort routine. Silence the warning by making the implicit
> truncation explicit.
The fls64() function only seems to deal with unsigned values, so
I don't see how it would change the sign.
> diff --git a/include/asm-generic/bitops/fls64.h
> b/include/asm-generic/bitops/fls64.h
> index 866f2b2304ff..9ad3ff12f454 100644
> --- a/include/asm-generic/bitops/fls64.h
> +++ b/include/asm-generic/bitops/fls64.h
> @@ -21,7 +21,7 @@ static __always_inline int fls64(__u64 x)
> __u32 h = x >> 32;
> if (h)
> return fls(h) + 32;
> - return fls(x);
> + return fls((__u32)x);
> }
Maybe this would be clearer with an explicit upper_32_bits()/
lower_32_bits() instead of the cast and the shift?
Arnd