* [PATCH] ARM: delay: avoid clang -Wtautological-constant warning
@ 2021-03-23 13:20 Arnd Bergmann
2021-03-23 13:30 ` Russell King - ARM Linux admin
2021-03-24 23:14 ` David Laight
0 siblings, 2 replies; 3+ messages in thread
From: Arnd Bergmann @ 2021-03-23 13:20 UTC (permalink / raw)
To: Russell King
Cc: Arnd Bergmann, Nathan Chancellor, Nick Desaulniers,
linux-arm-kernel, linux-kernel, clang-built-linux
From: Arnd Bergmann <arnd@arndb.de>
Passing an 8-bit constant into delay() triggers a warning when building
with 'make W=1' using clang:
drivers/clk/actions/owl-pll.c:182:2: error: result of comparison of constant 2000 with expression of type 'u8' (aka 'unsigned char') is always false [-Werror,-Wtautological-constant-out-of-range-compare]
udelay(pll_hw->delay);
^~~~~~~~~~~~~~~~~~~~~
arch/arm/include/asm/delay.h:84:9: note: expanded from macro 'udelay'
((n) > (MAX_UDELAY_MS * 1000) ? __bad_udelay() : \
~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~
arch/arm/mach-omap2/wd_timer.c:89:3: error: result of comparison of constant 2000 with expression of type 'u8' (aka 'unsigned char') is always false [-Werror,-Wtautological-constant-out-of-range-compare]
udelay(oh->class->sysc->srst_udelay);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Shut up the warning by adding a cast to a 64-bit number. A cast to 'int'
would usually be sufficient, but would fail to cause a link-time error
for large 64-bit constants.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
arch/arm/include/asm/delay.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/arm/include/asm/delay.h b/arch/arm/include/asm/delay.h
index 4f80b72372b4..1bb6417a3a83 100644
--- a/arch/arm/include/asm/delay.h
+++ b/arch/arm/include/asm/delay.h
@@ -81,7 +81,7 @@ extern void __bad_udelay(void);
#define udelay(n) \
(__builtin_constant_p(n) ? \
- ((n) > (MAX_UDELAY_MS * 1000) ? __bad_udelay() : \
+ ((u64)(n) > (MAX_UDELAY_MS * 1000) ? __bad_udelay() : \
__const_udelay((n) * UDELAY_MULT)) : \
__udelay(n))
--
2.29.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] ARM: delay: avoid clang -Wtautological-constant warning
2021-03-23 13:20 [PATCH] ARM: delay: avoid clang -Wtautological-constant warning Arnd Bergmann
@ 2021-03-23 13:30 ` Russell King - ARM Linux admin
2021-03-24 23:14 ` David Laight
1 sibling, 0 replies; 3+ messages in thread
From: Russell King - ARM Linux admin @ 2021-03-23 13:30 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Arnd Bergmann, Nathan Chancellor, Nick Desaulniers,
linux-arm-kernel, linux-kernel, clang-built-linux
On Tue, Mar 23, 2021 at 02:20:23PM +0100, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
>
> Passing an 8-bit constant into delay() triggers a warning when building
> with 'make W=1' using clang:
>
> drivers/clk/actions/owl-pll.c:182:2: error: result of comparison of constant 2000 with expression of type 'u8' (aka 'unsigned char') is always false [-Werror,-Wtautological-constant-out-of-range-compare]
> udelay(pll_hw->delay);
> ^~~~~~~~~~~~~~~~~~~~~
> arch/arm/include/asm/delay.h:84:9: note: expanded from macro 'udelay'
> ((n) > (MAX_UDELAY_MS * 1000) ? __bad_udelay() : \
> ~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~
> arch/arm/mach-omap2/wd_timer.c:89:3: error: result of comparison of constant 2000 with expression of type 'u8' (aka 'unsigned char') is always false [-Werror,-Wtautological-constant-out-of-range-compare]
> udelay(oh->class->sysc->srst_udelay);
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> Shut up the warning by adding a cast to a 64-bit number. A cast to 'int'
> would usually be sufficient, but would fail to cause a link-time error
> for large 64-bit constants.
What effect (if any) does this have on code generation when the argument
is not constant?
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
^ permalink raw reply [flat|nested] 3+ messages in thread
* RE: [PATCH] ARM: delay: avoid clang -Wtautological-constant warning
2021-03-23 13:20 [PATCH] ARM: delay: avoid clang -Wtautological-constant warning Arnd Bergmann
2021-03-23 13:30 ` Russell King - ARM Linux admin
@ 2021-03-24 23:14 ` David Laight
1 sibling, 0 replies; 3+ messages in thread
From: David Laight @ 2021-03-24 23:14 UTC (permalink / raw)
To: 'Arnd Bergmann', Russell King
Cc: Arnd Bergmann, Nathan Chancellor, Nick Desaulniers,
linux-arm-kernel, linux-kernel, clang-built-linux
From: Arnd Bergmann
> Sent: 23 March 2021 13:20
> Passing an 8-bit constant into delay() triggers a warning when building
> with 'make W=1' using clang:
>
> drivers/clk/actions/owl-pll.c:182:2: error: result of comparison of constant 2000 with expression of
> type 'u8' (aka 'unsigned char') is always false [-Werror,-Wtautological-constant-out-of-range-compare]
> udelay(pll_hw->delay);
> ^~~~~~~~~~~~~~~~~~~~~
> arch/arm/include/asm/delay.h:84:9: note: expanded from macro 'udelay'
> ((n) > (MAX_UDELAY_MS * 1000) ? __bad_udelay() : \
> ~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~
> arch/arm/mach-omap2/wd_timer.c:89:3: error: result of comparison of constant 2000 with expression of
> type 'u8' (aka 'unsigned char') is always false [-Werror,-Wtautological-constant-out-of-range-compare]
> udelay(oh->class->sysc->srst_udelay);
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> Shut up the warning by adding a cast to a 64-bit number. A cast to 'int'
> would usually be sufficient, but would fail to cause a link-time error
> for large 64-bit constants.
Adding 0u probably has the desired effect - without any side effects of a cast.
David
>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
> arch/arm/include/asm/delay.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/arm/include/asm/delay.h b/arch/arm/include/asm/delay.h
> index 4f80b72372b4..1bb6417a3a83 100644
> --- a/arch/arm/include/asm/delay.h
> +++ b/arch/arm/include/asm/delay.h
> @@ -81,7 +81,7 @@ extern void __bad_udelay(void);
>
> #define udelay(n) \
> (__builtin_constant_p(n) ? \
> - ((n) > (MAX_UDELAY_MS * 1000) ? __bad_udelay() : \
> + ((u64)(n) > (MAX_UDELAY_MS * 1000) ? __bad_udelay() : \
> __const_udelay((n) * UDELAY_MULT)) : \
> __udelay(n))
>
> --
> 2.29.2
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-03-24 23:15 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-23 13:20 [PATCH] ARM: delay: avoid clang -Wtautological-constant warning Arnd Bergmann
2021-03-23 13:30 ` Russell King - ARM Linux admin
2021-03-24 23:14 ` David Laight
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).