Re: [PATCH 3/9] Kbuild: avoid duplicate warning options

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, Aug 12, 2023 at 5:50 PM Arnd Bergmann <arnd@xxxxxxxxxx> wrote:
>
> From: Arnd Bergmann <arnd@xxxxxxxx>
>
> 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@xxxxxxxx>
> ---
>  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




[Index of Archives]     [Linux Kernel]     [Kernel Newbies]     [x86 Platform Driver]     [Netdev]     [Linux Wireless]     [Netfilter]     [Bugtraq]     [Linux Filesystems]     [Yosemite Discussion]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Device Mapper]

  Powered by Linux