Skip to contentSkip to conversation

ARM: delay: avoid clang -Wtautological-constant warning

PATCH In review Arnd Bergmann 3 participants 3 messages Mar 23, 2021 – Mar 24, 2021 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ARM: delay: avoid clang -Wtautological-constant warning

From: Arnd Bergmann <[email protected]>

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.

---
 arch/arm/include/asm/delay.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/include/asm/delay.h +1 -1
index 4f80b72372b4..1bb6417a3a83 100644
@@ -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))
 
Signature · 1 line
2.29.2
#1 lore raw
Quoted 15 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

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);
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Quoted 3 lines

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?

Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
#2 lore raw
In reply to Arnd Bergmann

From: Arnd Bergmann

Quoted 16 lines

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);
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Quoted 3 lines

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

Quoted 20 lines
---
 arch/arm/include/asm/delay.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/include/asm/delay.h +1 -2
index 4f80b72372b4..1bb6417a3a83 100644
@@ -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))
 
--
Quoted 1 line

2.29.2

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)