[PATCH 1/4] x86/cpufeatures: Make {REQUIRED,DISABLED}_MASK_BIT_SET() return 0 or 1
From: Vineet Gupta
Date: Wed Nov 04 2026 - 11:16:45 EST
GCC 17 adds -Wconstant-logical-operand to -Wall. It warns when an operand
of && or || folds to a constant other than 0 or 1. An x86 defconfig build
with CONFIG_WERROR=y now fails in prepare0:
arch/x86/include/asm/cpufeature.h:72:36: error: use of logical '&&' with constant operand '4194304' [-Werror=constant-logical-operand]
The *_MASK_BIT_SET() macros used to be || chains of
CHECK_BIT_IN_MASK_WORD(), so the result was 0 or 1.
Commit da414d34b555 ("x86/cpufeatures: Use AWK to generate
{REQUIRED|DISABLED}_MASK_BIT_SET in <asm/cpufeaturemasks.h>") changed
them to a ternary chain masked with (1U << bit). The result is now the
raw bit value. cpu_feature_enabled(), cpu_has() and this_cpu_has() use
this value as an && operand. clang has the same warning, but it does not
check an operator that comes from a macro expansion.
Wrap the generated expression in !!() to restore the 0 or 1 result. All
users test the value as a truth value, so the generated code does not
change.
Fixes: da414d34b555 ("x86/cpufeatures: Use AWK to generate {REQUIRED|DISABLED}_MASK_BIT_SET in <asm/cpufeaturemasks.h>")
Signed-off-by: Vineet Gupta <vineet.gupta@xxxxxxxxx>
---
arch/x86/tools/cpufeaturemasks.awk | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/x86/tools/cpufeaturemasks.awk b/arch/x86/tools/cpufeaturemasks.awk
index 173d5bf2d999..a7856f874a6b 100755
--- a/arch/x86/tools/cpufeaturemasks.awk
+++ b/arch/x86/tools/cpufeaturemasks.awk
@@ -75,13 +75,13 @@ END {
printf "#define %s_MASK%d\t0x%08xU\n", s, i, masks[i];
printf "\n#define %s_MASK_BIT_SET(x)\t\t\t\\\n", s;
- printf "\t((\t\t\t\t\t";
+ printf "\t(!!((\t\t\t\t\t";
for (i = 0; i < ncapints; i++) {
if (masks[i])
printf "\t\\\n\t\t((x) >> 5) == %2d ? %s_MASK%d :", i, s, i;
}
printf " 0\t\\\n";
- printf "\t) & (1U << ((x) & 31)))\n\n";
+ printf "\t) & (1U << ((x) & 31))))\n\n";
}
printf "#endif /* _ASM_X86_CPUFEATUREMASKS_H */\n";
--
2.53.0-Meta