From nobody Wed Apr 8 19:54:50 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A8182ECAAA1 for ; Fri, 28 Oct 2022 20:00:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230123AbiJ1UAj (ORCPT ); Fri, 28 Oct 2022 16:00:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35310 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230085AbiJ1UAf (ORCPT ); Fri, 28 Oct 2022 16:00:35 -0400 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2E7181688 for ; Fri, 28 Oct 2022 13:00:34 -0700 (PDT) Received: by mail-ej1-x62c.google.com with SMTP id n12so15375644eja.11 for ; Fri, 28 Oct 2022 13:00:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=tZiFH0DYxlEsNHskvYIaXjWqH/sLniKamLHMSjoq7eo=; b=YXlezLwWzDUg0ovuvpImFTCOi4u+xvViEIK0ZbGqywfK5fKYqpUpKEGgA6izT7YMFg eFdLjf8BToJpjDs5AOdJdHa8Zxs/tO7ZdlpCtnalBOvu8WW4I15MQS9KOzg4Ah3Wimyj BkrOQrNMFLv0lYET0q042G0EjKLYDujQAd/hwqlWSXF1vCiMmmOHrKe0VPIttbsXHSKL zDQdzyC+9Jya9jkn+DFinJ/gqT5Ei9m6N3cyZxq3BmDvL6auwbgI7meinkK/DWbaVzNc MIwIDCu4zvKeZnH5/j5NFbKpPNPUnsyAWgeNDok4YsCQaJonLxe5d1etOj62RvtXAn24 HYRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=tZiFH0DYxlEsNHskvYIaXjWqH/sLniKamLHMSjoq7eo=; b=kbF15AzvpLOeMlooXnhixf298E7SL/wrQnFVUVJFB1J/qaw8s4bqTsbElJ+bhkkPUs A9gmlUm+ZIkZKfDQKJfEKRjiK14UQdt5W1MMPMz67Qh4ZI4rZYuMghl4nOgn/tBzuLUB gmlOgh3vWV+SrzwXnDEIEfCUb+axLqQl9Ic0x54cS2aYpunOPq4PWhhOKq14ckH5n7/I daNJoGV9oe16Sz3SxNDFGw4IJNJJuHGmw6YapilTp2a6syI7xMhUtMujycJXrR/w3QJi EkZ2dA5WEoGEsIvmJRCq0zdK77044Vyhbho7+BAF+cHBOmzNAjFR03lPr0GZLn5zZ78V /uCg== X-Gm-Message-State: ACrzQf1VMIUUhh1KwGswYwkQjoVr/DS8OCAb3c1ZF8PAV0gadfb7xg/e VnDzVrvDNzRi+u4yHkjGZA== X-Google-Smtp-Source: AMsMyM7YTqVgKSA3PAn5GzG78RedkorzQDl8NSWGWSM7nkRrfS7w/bxpIHOvmbwTQKcvOlS9JZt/DQ== X-Received: by 2002:a17:907:75c8:b0:78d:b646:e768 with SMTP id jl8-20020a17090775c800b0078db646e768mr907428ejc.432.1666987233242; Fri, 28 Oct 2022 13:00:33 -0700 (PDT) Received: from p183 ([46.53.251.139]) by smtp.gmail.com with ESMTPSA id p20-20020a1709061b5400b0073d7b876621sm308686ejg.205.2022.10.28.13.00.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Oct 2022 13:00:32 -0700 (PDT) Date: Fri, 28 Oct 2022 23:00:31 +0300 From: Alexey Dobriyan To: torvalds@linux-foundation.org Cc: akpm@linux-foundation.org, linux-kernel@vger.kernel.org, catalin.marinas@arm.com, will@kernel.org, rafael.j.wysocki@intel.com, masahiroy@kernel.org Subject: [PATCH] kbuild: drop -Wdeclaration-after-statement Message-ID: MIME-Version: 1.0 Content-Disposition: inline Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 =3D f(); This will make one rare class of bugs even more rare: int a; ... f(&a); // bug, typo, should be f(&x) ... a =3D g(); If declarations are allowed anywhere, the above would be written as f(&a); int a =3D g(); and it would not compile because "a" lives for less LOC window. Signed-off-by: Alexey Dobriyan --- 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 =3D rustc HOSTPKG_CONFIG =3D pkg-config =20 KBUILD_USERHOSTCFLAGS :=3D -Wall -Wmissing-prototypes -Wstrict-prototypes \ - -O2 -fomit-frame-pointer -std=3Dgnu11 \ - -Wdeclaration-after-statement + -O2 -fomit-frame-pointer -std=3Dgnu11 KBUILD_USERCFLAGS :=3D $(KBUILD_USERHOSTCFLAGS) $(USERCFLAGS) KBUILD_USERLDFLAGS :=3D $(USERLDFLAGS) =20 @@ -1011,9 +1010,6 @@ endif # arch Makefile may override CC so keep this after arch Makefile is includ= ed NOSTDINC_FLAGS +=3D -nostdinc =20 -# warn about C99 declaration after statement -KBUILD_CFLAGS +=3D -Wdeclaration-after-statement - # Variable Length Arrays (VLAs) should not be used anywhere in the kernel KBUILD_CFLAGS +=3D -Wvla =20 --- a/arch/arm64/kernel/vdso32/Makefile +++ b/arch/arm64/kernel/vdso32/Makefile @@ -68,11 +68,9 @@ VDSO_CFLAGS +=3D -Wall -Wundef -Wstrict-prototypes -Wno-= trigraphs \ -fno-strict-aliasing -fno-common \ -Werror-implicit-function-declaration \ -Wno-format-security \ - -Wdeclaration-after-statement \ -std=3Dgnu11 VDSO_CFLAGS +=3D -O2 # Some useful compiler-dependent flags from top-level Makefile -VDSO_CFLAGS +=3D $(call cc32-option,-Wdeclaration-after-statement,) VDSO_CFLAGS +=3D $(call cc32-option,-Wno-pointer-sign) VDSO_CFLAGS +=3D -fno-strict-overflow VDSO_CFLAGS +=3D $(call cc32-option,-Werror=3Dstrict-prototypes) --- a/tools/power/acpi/Makefile.config +++ b/tools/power/acpi/Makefile.config @@ -63,7 +63,6 @@ OPTIMIZATION :=3D $(call cc-supports,-Os,-O2) =20 WARNINGS :=3D -Wall WARNINGS +=3D $(call cc-supports,-Wstrict-prototypes) -WARNINGS +=3D $(call cc-supports,-Wdeclaration-after-statement) =20 KERNEL_INCLUDE :=3D $(OUTPUT)include ACPICA_INCLUDE :=3D $(srctree)/../../../drivers/acpi/acpica --- a/tools/power/cpupower/Makefile +++ b/tools/power/cpupower/Makefile @@ -118,7 +118,6 @@ OPTIMIZATION :=3D $(call cc-supports,-Os,-O2) =20 WARNINGS :=3D -Wall -Wchar-subscripts -Wpointer-arith -Wsign-compare WARNINGS +=3D $(call cc-supports,-Wno-pointer-sign) -WARNINGS +=3D $(call cc-supports,-Wdeclaration-after-statement) WARNINGS +=3D -Wshadow =20 override CFLAGS +=3D -DVERSION=3D\"$(VERSION)\" -DPACKAGE=3D\"$(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 :=3D -Wbad-function-cast -EXTRA_WARNINGS +=3D -Wdeclaration-after-statement EXTRA_WARNINGS +=3D -Wformat-security EXTRA_WARNINGS +=3D -Wformat-y2k EXTRA_WARNINGS +=3D -Winit-self