public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kbuild: drop -Wdeclaration-after-statement
@ 2022-10-28 20:00 Alexey Dobriyan
  2022-10-28 20:29 ` Linus Torvalds
  0 siblings, 1 reply; 5+ messages in thread
From: Alexey Dobriyan @ 2022-10-28 20:00 UTC (permalink / raw)
  To: torvalds
  Cc: akpm, linux-kernel, catalin.marinas, will, rafael.j.wysocki,
	masahiroy

Putting declarations in the beginning of the block is an afterfact from
single pass compiler era. Compiler would parse all declarations, layout
stack frame and proceed to generate code.

In C initialisers can be arbitrarily complex so there is no fundamental
distinction between initialiser and regular code.
-Wno-declaration-after-statement creates such distinction which is
entirely artificial.

This will save LOC in the long run because people would write code like
this:

	int a = f();

This will make one rare class of bugs even more rare:

	int a;
	...
	f(&a);	// bug, typo, should be f(&x)
	...
	a = g();

If declarations are allowed anywhere, the above would be written as

	f(&a);
	int a = g();

and it would not compile because "a" lives for less LOC window.

Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
---

 Makefile                          |    6 +-----
 arch/arm64/kernel/vdso32/Makefile |    2 --
 tools/power/acpi/Makefile.config  |    1 -
 tools/power/cpupower/Makefile     |    1 -
 tools/scripts/Makefile.include    |    1 -
 5 files changed, 1 insertion(+), 10 deletions(-)

--- a/Makefile
+++ b/Makefile
@@ -452,8 +452,7 @@ HOSTRUSTC = rustc
 HOSTPKG_CONFIG	= pkg-config
 
 KBUILD_USERHOSTCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes \
-			 -O2 -fomit-frame-pointer -std=gnu11 \
-			 -Wdeclaration-after-statement
+			 -O2 -fomit-frame-pointer -std=gnu11
 KBUILD_USERCFLAGS  := $(KBUILD_USERHOSTCFLAGS) $(USERCFLAGS)
 KBUILD_USERLDFLAGS := $(USERLDFLAGS)
 
@@ -1011,9 +1010,6 @@ endif
 # arch Makefile may override CC so keep this after arch Makefile is included
 NOSTDINC_FLAGS += -nostdinc
 
-# warn about C99 declaration after statement
-KBUILD_CFLAGS += -Wdeclaration-after-statement
-
 # Variable Length Arrays (VLAs) should not be used anywhere in the kernel
 KBUILD_CFLAGS += -Wvla
 
--- a/arch/arm64/kernel/vdso32/Makefile
+++ b/arch/arm64/kernel/vdso32/Makefile
@@ -68,11 +68,9 @@ VDSO_CFLAGS += -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
                -fno-strict-aliasing -fno-common \
                -Werror-implicit-function-declaration \
                -Wno-format-security \
-               -Wdeclaration-after-statement \
                -std=gnu11
 VDSO_CFLAGS  += -O2
 # Some useful compiler-dependent flags from top-level Makefile
-VDSO_CFLAGS += $(call cc32-option,-Wdeclaration-after-statement,)
 VDSO_CFLAGS += $(call cc32-option,-Wno-pointer-sign)
 VDSO_CFLAGS += -fno-strict-overflow
 VDSO_CFLAGS += $(call cc32-option,-Werror=strict-prototypes)
--- a/tools/power/acpi/Makefile.config
+++ b/tools/power/acpi/Makefile.config
@@ -63,7 +63,6 @@ OPTIMIZATION := $(call cc-supports,-Os,-O2)
 
 WARNINGS := -Wall
 WARNINGS += $(call cc-supports,-Wstrict-prototypes)
-WARNINGS += $(call cc-supports,-Wdeclaration-after-statement)
 
 KERNEL_INCLUDE := $(OUTPUT)include
 ACPICA_INCLUDE := $(srctree)/../../../drivers/acpi/acpica
--- a/tools/power/cpupower/Makefile
+++ b/tools/power/cpupower/Makefile
@@ -118,7 +118,6 @@ OPTIMIZATION := $(call cc-supports,-Os,-O2)
 
 WARNINGS := -Wall -Wchar-subscripts -Wpointer-arith -Wsign-compare
 WARNINGS += $(call cc-supports,-Wno-pointer-sign)
-WARNINGS += $(call cc-supports,-Wdeclaration-after-statement)
 WARNINGS += -Wshadow
 
 override CFLAGS += -DVERSION=\"$(VERSION)\" -DPACKAGE=\"$(PACKAGE)\" \
--- a/tools/scripts/Makefile.include
+++ b/tools/scripts/Makefile.include
@@ -21,7 +21,6 @@ endif
 # Include saner warnings here, which can catch bugs:
 #
 EXTRA_WARNINGS := -Wbad-function-cast
-EXTRA_WARNINGS += -Wdeclaration-after-statement
 EXTRA_WARNINGS += -Wformat-security
 EXTRA_WARNINGS += -Wformat-y2k
 EXTRA_WARNINGS += -Winit-self

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-10-29 11:47 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-28 20:00 [PATCH] kbuild: drop -Wdeclaration-after-statement Alexey Dobriyan
2022-10-28 20:29 ` Linus Torvalds
2022-10-28 20:55   ` Alexey Dobriyan
2022-10-28 21:11     ` Linus Torvalds
2022-10-29 11:47     ` David Laight

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox