History

Kbuild: use -Wdeclaration-after-statement

The kernel is moving from using `-std=gnu89` to `-std=gnu11`, permitting the use of additional C11 features such as for-loop initial declarations. One contentious aspect of C99 is that it permits mixed declarations and code, and for now at least, it seems preferable to enforce that declarations must come first. These warnings were already enabled in the kernel itself, but not for KBUILD_USERCFLAGS or the compat VDSO on arch/arm64, which uses a separate set of CFLAGS. This patch fixes an existing violation in modpost.c, which is not reported because of the missing flag in KBUILD_USERCFLAGS: | scripts/mod/modpost.c: In function ‘match’: | scripts/mod/modpost.c:837:3: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement] | 837 | const char *endp = p + strlen(p) - 1; | | ^~~~~

Mark Rutland committed 4 years ago

Commit 4d94f911 parent 13447943 files · +6 −2Browse files

Unified · Split

3 files
  1. Makefile +2 −1
  2. arch/arm64/kernel/vdso32/Makefile +1 −0
  3. scripts/mod/modpost.c +3 −1
Makefile+2−1
@@ -432,7 +432,8 @@ HOSTCXX = g++ · 431 unmodified lines
432endif432endif
433 433
434export KBUILD_USERCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes \434export KBUILD_USERCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes \
435 -O2 -fomit-frame-pointer -std=gnu89435 -O2 -fomit-frame-pointer -std=gnu89 \
436 -Wdeclaration-after-statement
436export KBUILD_USERLDFLAGS :=437export KBUILD_USERLDFLAGS :=
437 438
438KBUILD_HOSTCFLAGS := $(KBUILD_USERCFLAGS) $(HOST_LFS_CFLAGS) $(HOSTCFLAGS)439KBUILD_HOSTCFLAGS := $(KBUILD_USERCFLAGS) $(HOST_LFS_CFLAGS) $(HOSTCFLAGS)
arch/arm64/kernel/vdso32/Makefile+1−0
@@ -68,6 +68,7 @@ VDSO_CFLAGS += -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \ · 67 unmodified lines
68 -fno-strict-aliasing -fno-common \68 -fno-strict-aliasing -fno-common \
69 -Werror-implicit-function-declaration \69 -Werror-implicit-function-declaration \
70 -Wno-format-security \70 -Wno-format-security \
71 -Wdeclaration-after-statement \
71 -std=gnu8972 -std=gnu89
72VDSO_CFLAGS += -O273VDSO_CFLAGS += -O2
73# Some useful compiler-dependent flags from top-level Makefile74# Some useful compiler-dependent flags from top-level Makefile
scripts/mod/modpost.c+3−1
@@ -833,8 +833,10 @@ static int match(const char *sym, const char * const pat[]) · 832 unmodified lines
833{833{
834 const char *p;834 const char *p;
835 while (*pat) {835 while (*pat) {
836 const char *endp;
837
836 p = *pat++;838 p = *pat++;
837 const char *endp = p + strlen(p) - 1;839 endp = p + strlen(p) - 1;
838 840
839 /* "*foo*" */841 /* "*foo*" */
840 if (*p == '*' && *endp == '*') {842 if (*p == '*' && *endp == '*') {