Skip to content

Commit

Permalink
Kbuild: use -Wdeclaration-after-statement
Browse files Browse the repository at this point in the history
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;
|       |   ^~~~~

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
[arnd: don't add a duplicate flag to the default set, update changelog]
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Nathan Chancellor <nathan@kernel.org>
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
Tested-by: Sedat Dilek <sedat.dilek@gmail.com> # LLVM/Clang v13.0.0 (x86-64)
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
  • Loading branch information
Mark Rutland authored and Masahiro Yamada committed Mar 13, 2022
1 parent 1344794 commit 4d94f91
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,8 @@ HOSTCXX = g++
endif

export KBUILD_USERCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes \
-O2 -fomit-frame-pointer -std=gnu89
-O2 -fomit-frame-pointer -std=gnu89 \
-Wdeclaration-after-statement
export KBUILD_USERLDFLAGS :=

KBUILD_HOSTCFLAGS := $(KBUILD_USERCFLAGS) $(HOST_LFS_CFLAGS) $(HOSTCFLAGS)
Expand Down
1 change: 1 addition & 0 deletions arch/arm64/kernel/vdso32/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ VDSO_CFLAGS += -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
-fno-strict-aliasing -fno-common \
-Werror-implicit-function-declaration \
-Wno-format-security \
-Wdeclaration-after-statement \
-std=gnu89
VDSO_CFLAGS += -O2
# Some useful compiler-dependent flags from top-level Makefile
Expand Down
4 changes: 3 additions & 1 deletion scripts/mod/modpost.c
Original file line number Diff line number Diff line change
Expand Up @@ -833,8 +833,10 @@ static int match(const char *sym, const char * const pat[])
{
const char *p;
while (*pat) {
const char *endp;

p = *pat++;
const char *endp = p + strlen(p) - 1;
endp = p + strlen(p) - 1;

/* "*foo*" */
if (*p == '*' && *endp == '*') {
Expand Down

0 comments on commit 4d94f91

Please sign in to comment.