eal: silence -Wconstant-logical-operand in RTE_IS_POWER_OF_2
PATCH 1/1 eal: silence -Wconstant-logical-operand in RTE_IS_POWER_OF_2
Newer GCC warns when a non-boolean constant is an operand of &&, which trips whenever RTE_IS_POWER_OF_2 is used in a static_assert with a power-of-two literal. Make the zero check explicit.
--- lib/eal/include/rte_bitops.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/eal/include/rte_bitops.h +1 -1
@@ -1299,7 +1299,7 @@ rte_fls_u64(uint64_t x)/** * Macro to return 1 if n is a power of 2, 0 otherwise */ -#define RTE_IS_POWER_OF_2 (n) ((n) && !(((n) - 1) & (n))) +#define RTE_IS_POWER_OF_2 (n) ((n) != 0 && !(((n) - 1) & (n)))/** * Returns true if n is a power of 2
Signature · 1 line
2.53.0
Quoted 8 lines · Stephen Hemminger
Newer GCC warns when a non-boolean constant is an operand of &&, which trips whenever
RTE_IS_POWER_OF_2is used in astatic_assertwith a power-of-two literal. Make the zero check explicit.Fixes 7c872b96983a ("hash: validate hash bucket entries while compiling")Signed-off-by Stephen Hemminger <[email protected]>
One further suggestion below, since you are changing this.
Quoted 9 lines
--- lib/eal/include/rte_bitops.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)lib/eal/include/rte_bitops.h +0
-0
lib/eal/include/rte_bitops.h rte_fls_u64(uint64_t x) · line 1303
Quoted 6 lines
lib/eal/include/rte_bitops.h +1
-1@@ -1299,7 +1299,7 @@ rte_fls_u64(uint64_t x)/** * Macro to return 1 if n is a power of 2, 0 otherwise */ -#define RTE_IS_POWER_OF_2 (n) ((n) && !(((n) - 1) & (n))) +#define RTE_IS_POWER_OF_2 (n) ((n) != 0 && !(((n) - 1) & (n)))
I'd also suggest changing the second part of the && to match, changing the "!" for explicit "== 0":
#define RTE_IS_POWER_OF_2(n) ((n) != 0 && (((n) - 1) & (n)) == 0)
Quoted 5 lines
lib/eal/include/rte_bitops.h +0
-0/** * Returns true if n is a power of 2 Signature · 1 line
2.53.0
Quoted 4 lines · On Mon, 18 May 2026 17:56:08 +0100 Bruce Richardson…
I'd also suggest changing the second part of the && to match, changing the "!" for explicit "== 0":
#define
RTE_IS_POWER_OF_2(n)((n) != 0 && (((n) - 1) & (n)) == 0)
Was heading for the smallest possible part
Quoted 17 lines · Stephen Hemminger
Newer GCC warns when a non-boolean constant is an operand of &&, which trips whenever
RTE_IS_POWER_OF_2is used in astatic_assertwith a power-of-two literal. Make the zero check explicit.Fixes 7c872b96983a ("hash: validate hash bucket entries while compiling")Signed-off-by Stephen Hemminger <[email protected]>--- lib/eal/include/rte_bitops.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)lib/eal/include/rte_bitops.h +0
-0
lib/eal/include/rte_bitops.h rte_fls_u64(uint64_t x) · line 1305
Quoted 8 lines
lib/eal/include/rte_bitops.h +1
-1@@ -1299,7 +1299,7 @@ rte_fls_u64(uint64_t x)/** * Macro to return 1 if n is a power of 2, 0 otherwise */ -#define RTE_IS_POWER_OF_2 (n) ((n) && !(((n) - 1) & (n))) +#define RTE_IS_POWER_OF_2 (n) ((n) != 0 && !(((n) - 1) & (n)))/** * Returns true if n is a power of 2
PATCH v2 1/1 eal: silence -Wconstant-logical-operand in RTE_IS_POWER_OF_2
In reply to Stephen HemmingerNewer GCC warns when a non-boolean constant is an operand of &&, which trips whenever RTE_IS_POWER_OF_2 is used in a static_assert with a power-of-two literal. Make the zero check explicit.
---
v2 - use suggestion to make both sides comparisons
Note: AI incorrectly complains about multiple evaluations in this macro
but that has always been the case, and has to be macro for use with static assert.
lib/eal/include/rte_bitops.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/eal/include/rte_bitops.h +1 -1
@@ -1299,7 +1299,7 @@ rte_fls_u64(uint64_t x)/** * Macro to return 1 if n is a power of 2, 0 otherwise */ -#define RTE_IS_POWER_OF_2 (n) ((n) && !(((n) - 1) & (n))) +#define RTE_IS_POWER_OF_2 (n) ((n) != 0 && (((n) - 1) & (n)) == 0)/** * Returns true if n is a power of 2
Signature · 1 line
2.53.0
Thomas Monjalon
Applied19/05/2026 15:49, Stephen Hemminger:
Quoted 4 lines
Newer GCC warns when a non-boolean constant is an operand of &&, which trips whenever
RTE_IS_POWER_OF_2is used in astatic_assertwith a power-of-two literal. Make the zero check explicit.
Quoted 8 lines
Fixes 7c872b96983a ("hash: validate hash bucket entries while compiling")Signed-off-by Stephen Hemminger <[email protected]>Acked-by Bruce Richardson <[email protected]>---
v2 - use suggestion to make both sides comparisons
Applied, thanks.