Makefile.extrawarn: enable -Wmissing-variable-declarations for W=1
PATCH 1/1 Makefile.extrawarn: enable -Wmissing-variable-declarations for W=1
I noticed Tom was sending patches where smatch was recommending annotating functions as static when no previous declaration existed. Surely the compiler could make such recommendations as well, I thought.
Looks like -Wmissing-variable-declarations can make such recommendations.
GCC just added support for this warning (gcc 14.1.0 will ship with support), and all versions of clang relevant to building the kernel support this flag.
--- scripts/Makefile.extrawarn | 1 + 1 file changed, 1 insertion(+)
scripts/Makefile.extrawarn +1 -0
@@ -32,6 +32,7 @@ KBUILD_CFLAGS += $(call cc-option, -Wunused-but-set-variable) KBUILD_CFLAGS += $(call cc-option, -Wunused-const-variable) KBUILD_CFLAGS += $(call cc-option, -Wpacked-not-aligned) KBUILD_CFLAGS += $(call cc-option, -Wstringop-truncation) +KBUILD_CFLAGS += $(call cc-option, -Wmissing-varibale-declarations) # The following turn off the warnings enabled by -Wextra KBUILD_CFLAGS += -Wno-missing-field-initializers KBUILD_CFLAGS += -Wno-sign-compare
---
base-commit: 52a93d39b17dc7eb98b6aa3edb93943248e03b2f
change-id: 20230807-missing_proto-0cb90ec6454c
Best regards,
Signature · 1 line
Nick Desaulniers <[email protected]>
Quoted 22 lines · Nick Desaulniers
I noticed Tom was sending patches where smatch was recommending annotating functions as static when no previous declaration existed. Surely the compiler could make such recommendations as well, I thought.
Looks like -Wmissing-variable-declarations can make such recommendations.
GCC just added support for this warning (gcc 14.1.0 will ship with support), and all versions of clang relevant to building the kernel support this flag.
Signed-off-by Nick Desaulniers <[email protected]>--- scripts/Makefile.extrawarn | 1 + 1 file changed, 1 insertion(+)scripts/Makefile.extrawarn +0
-0
scripts/Makefile.extrawarn KBUILD_CFLAGS += $(call cc-option, -Wunused-but-set-variable) · line 35
Quoted 4 lines
scripts/Makefile.extrawarn +1
-0@@ -32,6 +32,7 @@ KBUILD_CFLAGS += $(call cc-option, -Wunused-but-set-variable) KBUILD_CFLAGS += $(call cc-option, -Wunused-const-variable) KBUILD_CFLAGS += $(call cc-option, -Wpacked-not-aligned) KBUILD_CFLAGS += $(call cc-option, -Wstringop-truncation) +KBUILD_CFLAGS += $(call cc-option, -Wmissing-varibale-declarations)
^ sigh, misspelled
Quoted 12 lines
scripts/Makefile.extrawarn +0
-1# The following turn off the warnings enabled by -Wextra KBUILD_CFLAGS += -Wno-missing-field-initializers KBUILD_CFLAGS += -Wno-sign-compare ---base-commit:
52a93d39b17dc7eb98b6aa3edb93943248e03b2f
change-id: 20230807-missing_proto-0cb90ec6454cBest regards,
--
Nick Desaulniers <[email protected]>
Signature · 2 lines
Thanks, ~Nick Desaulniers
Nathan Chancellor
maintainerQuoted 4 lines · Nick Desaulniers
I noticed Tom was sending patches where smatch was recommending annotating functions as static when no previous declaration existed. Surely the compiler could make such recommendations as well, I thought.
Quoted 8 lines
Looks like -Wmissing-variable-declarations can make such recommendations.
GCC just added support for this warning (gcc 14.1.0 will ship with support), and all versions of clang relevant to building the kernel support this flag.
Signed-off-by Nick Desaulniers <[email protected]>
Any idea how many instances of this there are? At least x86_64 defconfig fails immediately with:
In file included from scripts/mod/devicetable-offsets.c:3:
In file included from include/linux/mod_devicetable.h:14:
In file included from include/linux/uuid.h:11:
In file included from include/linux/string.h:20:
In file included from arch/x86/include/asm/string.h:5:
In file included from arch/x86/include/asm/string_64.h:6:
In file included from include/linux/jump_label.h:112:
In file included from arch/x86/include/asm/jump_label.h:7:
arch/x86/include/asm/asm.h:208:24: error: no previous extern declaration for non-static variable 'current_stack_pointer' [-Werror,-Wmissing-variable-declarations]
208 | register unsigned long current_stack_pointer asm(_ASM_SP);
| ^
arch/x86/include/asm/asm.h:208:10: note: declare 'static' if the variable is not intended to be used outside of this translation unit
208 | register unsigned long current_stack_pointer asm(_ASM_SP);
| ^1 error generated.
scripts/Makefile.extrawarn KBUILD_CFLAGS += $(call cc-option, -Wunused-but-set-variable) · line 35
Quoted 13 lines
--- scripts/Makefile.extrawarn | 1 + 1 file changed, 1 insertion(+)scripts/Makefile.extrawarn +1
-0@@ -32,6 +32,7 @@ KBUILD_CFLAGS += $(call cc-option, -Wunused-but-set-variable) KBUILD_CFLAGS += $(call cc-option, -Wunused-const-variable) KBUILD_CFLAGS += $(call cc-option, -Wpacked-not-aligned) KBUILD_CFLAGS += $(call cc-option, -Wstringop-truncation) +KBUILD_CFLAGS += $(call cc-option, -Wmissing-varibale-declarations)
^ variable
Quoted 12 lines
scripts/Makefile.extrawarn +0
-1# The following turn off the warnings enabled by -Wextra KBUILD_CFLAGS += -Wno-missing-field-initializers KBUILD_CFLAGS += -Wno-sign-compare ---base-commit:
52a93d39b17dc7eb98b6aa3edb93943248e03b2f
change-id: 20230807-missing_proto-0cb90ec6454cBest regards,
Signature · 1 line
Nick Desaulniers <[email protected]>
Quoted 9 lines · Nathan Chancellor
Quoted 7 lines · Nick Desaulniers
I noticed Tom was sending patches where smatch was recommending annotating functions as static when no previous declaration existed. Surely the compiler could make such recommendations as well, I thought.
Looks like -Wmissing-variable-declarations can make such recommendations.
Quoted 8 lines
Quoted 5 lines
GCC just added support for this warning (gcc 14.1.0 will ship with support), and all versions of clang relevant to building the kernel support this flag.
Signed-off-by Nick Desaulniers <[email protected]>Any idea how many instances of this there are? At least
x86_64defconfig fails immediately with:
$ make LLVM=1 -j128 W=1 allnoconfig 2>log.txt $ grep -r Wmissing-variable-declarations log.txt | sort -u | wc -l 140 Though that's not perfectly filtered due to overlapping output due to -j 128.
Quoted 10 lines
In file included from
scripts/mod/devicetable-offsets.c:3:
In file included frominclude/linux/mod_devicetable.h:14:
In file included frominclude/linux/uuid.h:11:
In file included frominclude/linux/string.h:20:
In file included fromarch/x86/include/asm/string.h:5:
In file included fromarch/x86/include/asm/string_64.h:6:
In file included frominclude/linux/jump_label.h:112:
In file included fromarch/x86/include/asm/jump_label.h:7:
arch/x86/include/asm/asm.h:208:24: error: no previous extern declaration for non-static variable 'current_stack_pointer' [-Werror,-Wmissing-variable-declarations]
Quoted 5 lines
208 | register unsigned long current_stack_pointer asm(_ASM_SP);
| ^
arch/x86/include/asm/asm.h:208:10: note: declare 'static' if the variable is not intended to be used outside of this translation unit
208 | register unsigned long current_stack_pointer asm(_ASM_SP);
| ^Hmm...I wonder if clang and gcc should ignore variables with register storage for this warning.
Quoted 28 lines
1 error generated.
scripts/Makefile.extrawarn KBUILD_CFLAGS += $(call cc-option, -Wunused-but-set-variable) · line 35
Quoted 13 lines
--- scripts/Makefile.extrawarn | 1 + 1 file changed, 1 insertion(+)scripts/Makefile.extrawarn +1
-0@@ -32,6 +32,7 @@ KBUILD_CFLAGS += $(call cc-option, -Wunused-but-set-variable) KBUILD_CFLAGS += $(call cc-option, -Wunused-const-variable) KBUILD_CFLAGS += $(call cc-option, -Wpacked-not-aligned) KBUILD_CFLAGS += $(call cc-option, -Wstringop-truncation) +KBUILD_CFLAGS += $(call cc-option, -Wmissing-varibale-declarations)^ variable
Quoted 12 lines
scripts/Makefile.extrawarn +0
-1# The following turn off the warnings enabled by -Wextra KBUILD_CFLAGS += -Wno-missing-field-initializers KBUILD_CFLAGS += -Wno-sign-compare ---base-commit:
52a93d39b17dc7eb98b6aa3edb93943248e03b2f
change-id: 20230807-missing_proto-0cb90ec6454cBest regards,
--
Nick Desaulniers <[email protected]>
Signature · 2 lines
Thanks, ~Nick Desaulniers