diff mbox series

[3/9] Kbuild: avoid duplicate warning options

Message ID 20230811140327.3754597-4-arnd@kernel.org (mailing list archive)
State New, archived
Headers show
Series Kbuild: warning options cleanup and more warnings | expand

Commit Message

Arnd Bergmann Aug. 11, 2023, 2:03 p.m. UTC
From: Arnd Bergmann <arnd@arndb.de>

Some warning options are disabled at one place and then conditionally
re-enabled later in scripts/Makefile.extrawarn.

For consistency, rework this file so each of those warnings only
gets etiher enabled or disabled based on the W= flags but not both.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 scripts/Makefile.extrawarn | 43 +++++++++++++++++++++++---------------
 1 file changed, 26 insertions(+), 17 deletions(-)

Comments

Masahiro Yamada Aug. 12, 2023, 9:21 a.m. UTC | #1
On Sat, Aug 12, 2023 at 5:50 PM Arnd Bergmann <arnd@kernel.org> wrote:
>
> From: Arnd Bergmann <arnd@arndb.de>
>
> Some warning options are disabled at one place and then conditionally
> re-enabled later in scripts/Makefile.extrawarn.
>
> For consistency, rework this file so each of those warnings only
> gets etiher enabled or disabled based on the W= flags but not both.
>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  scripts/Makefile.extrawarn | 43 +++++++++++++++++++++++---------------
>  1 file changed, 26 insertions(+), 17 deletions(-)
>
> diff --git a/scripts/Makefile.extrawarn b/scripts/Makefile.extrawarn
> index 9cc0e52ebd7eb..8afbe4706ff11 100644
> --- a/scripts/Makefile.extrawarn
> +++ b/scripts/Makefile.extrawarn
> @@ -56,20 +56,12 @@ KBUILD_CFLAGS += -Wno-pointer-sign
>  # globally built with -Wcast-function-type.
>  KBUILD_CFLAGS += $(call cc-option, -Wcast-function-type)
>
> -# disable stringop warnings in gcc 8+
> -KBUILD_CFLAGS += $(call cc-disable-warning, stringop-truncation)
> -
>  # We'll want to enable this eventually, but it's not going away for 5.7 at least
>  KBUILD_CFLAGS += $(call cc-disable-warning, stringop-overflow)
>
>  # Another good warning that we'll want to enable eventually
>  KBUILD_CFLAGS += $(call cc-disable-warning, restrict)
>
> -# Enabled with W=2, disabled by default as noisy
> -ifdef CONFIG_CC_IS_GCC
> -KBUILD_CFLAGS += -Wno-maybe-uninitialized
> -endif
> -
>  # The allocators already balk at large sizes, so silence the compiler
>  # warnings for bounds checks involving those possible values. While
>  # -Wno-alloc-size-larger-than would normally be used here, earlier versions
> @@ -96,8 +88,6 @@ KBUILD_CFLAGS += $(call cc-option,-Werror=designated-init)
>  # Warn if there is an enum types mismatch
>  KBUILD_CFLAGS += $(call cc-option,-Wenum-conversion)
>
> -KBUILD_CFLAGS += $(call cc-disable-warning, packed-not-aligned)
> -
>  # backward compatibility
>  KBUILD_EXTRA_WARN ?= $(KBUILD_ENABLE_EXTRA_GCC_CHECKS)
>
> @@ -122,11 +112,6 @@ 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)
> -# The following turn off the warnings enabled by -Wextra
> -KBUILD_CFLAGS += -Wno-missing-field-initializers
> -KBUILD_CFLAGS += -Wno-sign-compare
> -KBUILD_CFLAGS += -Wno-type-limits
> -KBUILD_CFLAGS += -Wno-shift-negative-value
>
>  KBUILD_CPPFLAGS += -Wundef
>  KBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN1
> @@ -135,9 +120,12 @@ else
>
>  # Some diagnostics enabled by default are noisy.
>  # Suppress them by using -Wno... except for W=1.
> +KBUILD_CFLAGS += $(call cc-disable-warning, unused-but-set-variable)
> +KBUILD_CFLAGS += $(call cc-disable-warning, unused-const-variable)
> +KBUILD_CFLAGS += $(call cc-disable-warning, packed-not-aligned)
> +KBUILD_CFLAGS += $(call cc-disable-warning, stringop-truncation)
>
>  ifdef CONFIG_CC_IS_CLANG
> -KBUILD_CFLAGS += -Wno-initializer-overrides
>  # Clang before clang-16 would warn on default argument promotions.
>  ifneq ($(call clang-min-version, 160000),y)
>  # Disable -Wformat
> @@ -151,7 +139,6 @@ ifeq ($(call clang-min-version, 120000),y)
>  KBUILD_CFLAGS += -Wformat-insufficient-args
>  endif
>  endif
> -KBUILD_CFLAGS += -Wno-sign-compare
>  KBUILD_CFLAGS += $(call cc-disable-warning, pointer-to-enum-cast)
>  KBUILD_CFLAGS += -Wno-tautological-constant-out-of-range-compare
>  KBUILD_CFLAGS += $(call cc-disable-warning, unaligned-access)
> @@ -173,8 +160,25 @@ KBUILD_CFLAGS += -Wtype-limits
>  KBUILD_CFLAGS += $(call cc-option, -Wmaybe-uninitialized)
>  KBUILD_CFLAGS += $(call cc-option, -Wunused-macros)
>
> +ifdef CONFIG_CC_IS_CLANG
> +KBUILD_CFLAGS += -Winitializer-overrides
> +endif
> +
>  KBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN2
>
> +else
> +
> +# The following turn off the warnings enabled by -Wextra
> +KBUILD_CFLAGS += -Wno-missing-field-initializers
> +KBUILD_CFLAGS += -Wno-type-limits
> +KBUILD_CFLAGS += -Wno-shift-negative-value
> +
> +ifdef CONFIG_CC_IS_CLANG
> +KBUILD_CFLAGS += -Wno-initializer-overrides
> +else
> +KBUILD_CFLAGS += -Wno-maybe-uninitialized




GCC manual says -Wall implies -Wmaybe-uninitialized.

If you move -Wno-maybe-uninitialize to the "W != 2" part,
-Wmaybe-uninitialized is unneeded in the 'W == 2" part.

Maybe, the same applies to -Wunused-but-set-parameter.

Shall we drop warnings implied by another, or
is it clearer to explicitly add either -Wfoo or -Wno-foo?

If desired, we can do such a clean-up later, though.







--
Best Regards
Masahiro Yamada
Arnd Bergmann Aug. 12, 2023, 9:28 a.m. UTC | #2
On Sat, Aug 12, 2023, at 11:21, Masahiro Yamada wrote:
> On Sat, Aug 12, 2023 at 5:50 PM Arnd Bergmann <arnd@kernel.org> wrote:
>
> GCC manual says -Wall implies -Wmaybe-uninitialized.
>
> If you move -Wno-maybe-uninitialize to the "W != 2" part,
> -Wmaybe-uninitialized is unneeded in the 'W == 2" part.
>
> Maybe, the same applies to -Wunused-but-set-parameter.
>
> Shall we drop warnings implied by another, or
> is it clearer to explicitly add either -Wfoo or -Wno-foo?
>
> If desired, we can do such a clean-up later, though.

Right, we can probably drop that, I've gone back and forth
on this how to handle these. Some of the warnings are
handled differently between gcc and clang, or differently
between compiler versions, where they are sometimes
implied and sometimes need to be specified explicitly.

What I've tried to do here is to do the change in the least
invasive way to ensure that this larger patch does not
change the behavior. My preference would be for you
to merge it like this unless you see a bug, and then
do another cleanup pass where we remove the ones implied
by either -Wall or -Wextra on all known versions.

I'll be on vacation the next few weeks starting on
Tuesday and will be able to reply to emails, but won't
have a chance to sufficiently test any significant
reworks of my series before the merge window.

    Arnd
Masahiro Yamada Aug. 20, 2023, 1:38 a.m. UTC | #3
On Sun, Aug 13, 2023 at 2:45 AM Arnd Bergmann <arnd@arndb.de> wrote:
>
> On Sat, Aug 12, 2023, at 11:21, Masahiro Yamada wrote:
> > On Sat, Aug 12, 2023 at 5:50 PM Arnd Bergmann <arnd@kernel.org> wrote:
> >
> > GCC manual says -Wall implies -Wmaybe-uninitialized.
> >
> > If you move -Wno-maybe-uninitialize to the "W != 2" part,
> > -Wmaybe-uninitialized is unneeded in the 'W == 2" part.
> >
> > Maybe, the same applies to -Wunused-but-set-parameter.
> >
> > Shall we drop warnings implied by another, or
> > is it clearer to explicitly add either -Wfoo or -Wno-foo?
> >
> > If desired, we can do such a clean-up later, though.
>
> Right, we can probably drop that, I've gone back and forth
> on this how to handle these. Some of the warnings are
> handled differently between gcc and clang, or differently
> between compiler versions, where they are sometimes
> implied and sometimes need to be specified explicitly.
>
> What I've tried to do here is to do the change in the least
> invasive way to ensure that this larger patch does not
> change the behavior. My preference would be for you
> to merge it like this unless you see a bug, and then
> do another cleanup pass where we remove the ones implied
> by either -Wall or -Wextra on all known versions.
>
> I'll be on vacation the next few weeks starting on
> Tuesday and will be able to reply to emails, but won't
> have a chance to sufficiently test any significant
> reworks of my series before the merge window.
>
>     Arnd

Applied  to linux-kbuild. Thanks.
diff mbox series

Patch

diff --git a/scripts/Makefile.extrawarn b/scripts/Makefile.extrawarn
index 9cc0e52ebd7eb..8afbe4706ff11 100644
--- a/scripts/Makefile.extrawarn
+++ b/scripts/Makefile.extrawarn
@@ -56,20 +56,12 @@  KBUILD_CFLAGS += -Wno-pointer-sign
 # globally built with -Wcast-function-type.
 KBUILD_CFLAGS += $(call cc-option, -Wcast-function-type)
 
-# disable stringop warnings in gcc 8+
-KBUILD_CFLAGS += $(call cc-disable-warning, stringop-truncation)
-
 # We'll want to enable this eventually, but it's not going away for 5.7 at least
 KBUILD_CFLAGS += $(call cc-disable-warning, stringop-overflow)
 
 # Another good warning that we'll want to enable eventually
 KBUILD_CFLAGS += $(call cc-disable-warning, restrict)
 
-# Enabled with W=2, disabled by default as noisy
-ifdef CONFIG_CC_IS_GCC
-KBUILD_CFLAGS += -Wno-maybe-uninitialized
-endif
-
 # The allocators already balk at large sizes, so silence the compiler
 # warnings for bounds checks involving those possible values. While
 # -Wno-alloc-size-larger-than would normally be used here, earlier versions
@@ -96,8 +88,6 @@  KBUILD_CFLAGS += $(call cc-option,-Werror=designated-init)
 # Warn if there is an enum types mismatch
 KBUILD_CFLAGS += $(call cc-option,-Wenum-conversion)
 
-KBUILD_CFLAGS += $(call cc-disable-warning, packed-not-aligned)
-
 # backward compatibility
 KBUILD_EXTRA_WARN ?= $(KBUILD_ENABLE_EXTRA_GCC_CHECKS)
 
@@ -122,11 +112,6 @@  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)
-# The following turn off the warnings enabled by -Wextra
-KBUILD_CFLAGS += -Wno-missing-field-initializers
-KBUILD_CFLAGS += -Wno-sign-compare
-KBUILD_CFLAGS += -Wno-type-limits
-KBUILD_CFLAGS += -Wno-shift-negative-value
 
 KBUILD_CPPFLAGS += -Wundef
 KBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN1
@@ -135,9 +120,12 @@  else
 
 # Some diagnostics enabled by default are noisy.
 # Suppress them by using -Wno... except for W=1.
+KBUILD_CFLAGS += $(call cc-disable-warning, unused-but-set-variable)
+KBUILD_CFLAGS += $(call cc-disable-warning, unused-const-variable)
+KBUILD_CFLAGS += $(call cc-disable-warning, packed-not-aligned)
+KBUILD_CFLAGS += $(call cc-disable-warning, stringop-truncation)
 
 ifdef CONFIG_CC_IS_CLANG
-KBUILD_CFLAGS += -Wno-initializer-overrides
 # Clang before clang-16 would warn on default argument promotions.
 ifneq ($(call clang-min-version, 160000),y)
 # Disable -Wformat
@@ -151,7 +139,6 @@  ifeq ($(call clang-min-version, 120000),y)
 KBUILD_CFLAGS += -Wformat-insufficient-args
 endif
 endif
-KBUILD_CFLAGS += -Wno-sign-compare
 KBUILD_CFLAGS += $(call cc-disable-warning, pointer-to-enum-cast)
 KBUILD_CFLAGS += -Wno-tautological-constant-out-of-range-compare
 KBUILD_CFLAGS += $(call cc-disable-warning, unaligned-access)
@@ -173,8 +160,25 @@  KBUILD_CFLAGS += -Wtype-limits
 KBUILD_CFLAGS += $(call cc-option, -Wmaybe-uninitialized)
 KBUILD_CFLAGS += $(call cc-option, -Wunused-macros)
 
+ifdef CONFIG_CC_IS_CLANG
+KBUILD_CFLAGS += -Winitializer-overrides
+endif
+
 KBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN2
 
+else
+
+# The following turn off the warnings enabled by -Wextra
+KBUILD_CFLAGS += -Wno-missing-field-initializers
+KBUILD_CFLAGS += -Wno-type-limits
+KBUILD_CFLAGS += -Wno-shift-negative-value
+
+ifdef CONFIG_CC_IS_CLANG
+KBUILD_CFLAGS += -Wno-initializer-overrides
+else
+KBUILD_CFLAGS += -Wno-maybe-uninitialized
+endif
+
 endif
 
 #
@@ -196,6 +200,11 @@  KBUILD_CFLAGS += $(call cc-option, -Wpacked-bitfield-compat)
 
 KBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN3
 
+else
+
+# The following turn off the warnings enabled by -Wextra
+KBUILD_CFLAGS += -Wno-sign-compare
+
 endif
 
 #