[PATCH 3/5] kbuild: disable -Wunused-but-set-variable after -Wall

Ahmad Fatoum a.fatoum at pengutronix.de
Fri Sep 4 00:59:15 PDT 2026


From: Ahmad Fatoum <a.fatoum at barebox.org>

The top-level Makefile passes -Wno-unused-but-set-variable before
scripts/Makefile.warn adds -Wall. GCC keeps the warning disabled, but
clang processes options in order and re-enables it, failing dozens of
files with CONFIG_WERROR=y:

  drivers/video/edid.c:390:6: error: variable 'hfmin' set but not used [-Werror,-Wunused-but-set-variable]

Move the option after -Wall in scripts/Makefile.warn, where Linux'
scripts/Makefile.extrawarn has it.

Assisted-by: Claude:fable-5
Signed-off-by: Ahmad Fatoum <a.fatoum at barebox.org>
---
 Makefile              | 4 ----
 scripts/Makefile.warn | 5 +++++
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/Makefile b/Makefile
index be81ac70403d..8762d2ae68b9 100644
--- a/Makefile
+++ b/Makefile
@@ -833,10 +833,6 @@ endif
 # Clear used registers at func exit (to reduce data lifetime and ROP gadgets).
 KBUILD_CFLAGS-$(CONFIG_ZERO_CALL_USED_REGS)	+= -fzero-call-used-regs=used-gpr
 
-# This warning generated too much noise in a regular build.
-# Use make W=1 to enable this warning (see scripts/Makefile.build)
-KBUILD_CFLAGS += $(call cc-disable-warning, unused-but-set-variable)
-
 KBUILD_CFLAGS += $(call cc-disable-warning, trampolines)
 
 KBUILD_CFLAGS += $(call cc-option, -fno-delete-null-pointer-checks,)
diff --git a/scripts/Makefile.warn b/scripts/Makefile.warn
index a39c8223352a..393f7fd522c8 100644
--- a/scripts/Makefile.warn
+++ b/scripts/Makefile.warn
@@ -43,6 +43,11 @@ endif
 # disable pointer signed / unsigned warnings in gcc 4.0
 KBUILD_CFLAGS += -Wno-pointer-sign
 
+# Some diagnostics enabled by default are noisy. Unlike GCC, Clang re-enables
+# them when -Wall is passed later on the command line, so the -Wno... options
+# must come after -Wall
+KBUILD_CFLAGS += $(call cc-disable-warning, unused-but-set-variable)
+
 #
 # W=e and CONFIG_WERROR - error out on warnings
 #
-- 
2.47.3




More information about the barebox mailing list