diff mbox series

[5/9] extrawarn: enable format and stringop overflow warnings in W=1

Message ID 20230811140327.3754597-6-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>

The stringop and format warnings got disabled globally when they were
newly introduced in commit bd664f6b3e376 ("disable new gcc-7.1.1 warnings
for now"), 217c3e0196758 ("disable stringop truncation warnings for now")
and 5a76021c2eff7 ("gcc-10: disable 'stringop-overflow' warning for now").

In all cases, the sentiment at the time was that the warnings are
useful, and we actually addressed a number of real bugs based on
them, but we never managed to eliminate them all because even the
build bots using W=1 builds only see the -Wstringop-truncation
warnings that are enabled at that level.

Move these into the W=1 section to give them a larger build coverage
and actually eliminate them over time.

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

Comments

Masahiro Yamada Aug. 12, 2023, 1:10 p.m. UTC | #1
On Sat, Aug 12, 2023 at 10:50 AM Arnd Bergmann <arnd@kernel.org> wrote:
>
> From: Arnd Bergmann <arnd@arndb.de>
>
> The stringop and format warnings got disabled globally when they were
> newly introduced in commit bd664f6b3e376 ("disable new gcc-7.1.1 warnings
> for now"), 217c3e0196758 ("disable stringop truncation warnings for now")
> and 5a76021c2eff7 ("gcc-10: disable 'stringop-overflow' warning for now").
>
> In all cases, the sentiment at the time was that the warnings are
> useful, and we actually addressed a number of real bugs based on
> them, but we never managed to eliminate them all because even the
> build bots using W=1 builds only see the -Wstringop-truncation
> warnings that are enabled at that level.
>
> Move these into the W=1 section to give them a larger build coverage
> and actually eliminate them over time.
>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  scripts/Makefile.extrawarn | 11 ++++++-----
>  1 file changed, 6 insertions(+), 5 deletions(-)
>
> diff --git a/scripts/Makefile.extrawarn b/scripts/Makefile.extrawarn
> index 87bfe153198f1..ec528972371fa 100644
> --- a/scripts/Makefile.extrawarn
> +++ b/scripts/Makefile.extrawarn
> @@ -16,8 +16,6 @@ KBUILD_CFLAGS += -Werror=strict-prototypes
>  KBUILD_CFLAGS += -Wno-format-security
>  KBUILD_CFLAGS += -Wno-trigraphs
>  KBUILD_CFLAGS += $(call cc-disable-warning,frame-address,)
> -KBUILD_CFLAGS += $(call cc-disable-warning, format-truncation)
> -KBUILD_CFLAGS += $(call cc-disable-warning, format-overflow)
>  KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member)
>
>  ifneq ($(CONFIG_FRAME_WARN),0)
> @@ -56,9 +54,6 @@ KBUILD_CFLAGS += -Wno-pointer-sign
>  # globally built with -Wcast-function-type.
>  KBUILD_CFLAGS += $(call cc-option, -Wcast-function-type)
>
> -# 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)
>
> @@ -111,6 +106,9 @@ KBUILD_CFLAGS += -Wmissing-include-dirs
>  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, -Wformat-overflow)
> +KBUILD_CFLAGS += $(call cc-option, -Wformat-truncation)


These are redundant because -Wall implies
-Wformat-overflow and -Wformat-truncation
according to the GCC manual.
Masahiro Yamada Aug. 20, 2023, 1:40 a.m. UTC | #2
On Sat, Aug 12, 2023 at 10:10 PM Masahiro Yamada <masahiroy@kernel.org> wrote:
>
> On Sat, Aug 12, 2023 at 10:50 AM Arnd Bergmann <arnd@kernel.org> wrote:
> >
> > From: Arnd Bergmann <arnd@arndb.de>
> >
> > The stringop and format warnings got disabled globally when they were
> > newly introduced in commit bd664f6b3e376 ("disable new gcc-7.1.1 warnings
> > for now"), 217c3e0196758 ("disable stringop truncation warnings for now")
> > and 5a76021c2eff7 ("gcc-10: disable 'stringop-overflow' warning for now").
> >
> > In all cases, the sentiment at the time was that the warnings are
> > useful, and we actually addressed a number of real bugs based on
> > them, but we never managed to eliminate them all because even the
> > build bots using W=1 builds only see the -Wstringop-truncation
> > warnings that are enabled at that level.
> >
> > Move these into the W=1 section to give them a larger build coverage
> > and actually eliminate them over time.
> >
> > Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> > ---
> >  scripts/Makefile.extrawarn | 11 ++++++-----
> >  1 file changed, 6 insertions(+), 5 deletions(-)
> >
> > diff --git a/scripts/Makefile.extrawarn b/scripts/Makefile.extrawarn
> > index 87bfe153198f1..ec528972371fa 100644
> > --- a/scripts/Makefile.extrawarn
> > +++ b/scripts/Makefile.extrawarn
> > @@ -16,8 +16,6 @@ KBUILD_CFLAGS += -Werror=strict-prototypes
> >  KBUILD_CFLAGS += -Wno-format-security
> >  KBUILD_CFLAGS += -Wno-trigraphs
> >  KBUILD_CFLAGS += $(call cc-disable-warning,frame-address,)
> > -KBUILD_CFLAGS += $(call cc-disable-warning, format-truncation)
> > -KBUILD_CFLAGS += $(call cc-disable-warning, format-overflow)
> >  KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member)
> >
> >  ifneq ($(CONFIG_FRAME_WARN),0)
> > @@ -56,9 +54,6 @@ KBUILD_CFLAGS += -Wno-pointer-sign
> >  # globally built with -Wcast-function-type.
> >  KBUILD_CFLAGS += $(call cc-option, -Wcast-function-type)
> >
> > -# 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)
> >
> > @@ -111,6 +106,9 @@ KBUILD_CFLAGS += -Wmissing-include-dirs
> >  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, -Wformat-overflow)
> > +KBUILD_CFLAGS += $(call cc-option, -Wformat-truncation)
>
>
> These are redundant because -Wall implies
> -Wformat-overflow and -Wformat-truncation
> according to the GCC manual.
>
>
>
>
> --
> Best Regards
> Masahiro Yamada


Applied  to linux-kbuild. Thanks.
Nick Desaulniers Aug. 21, 2023, 6:26 p.m. UTC | #3
On Sat, Aug 12, 2023 at 6:11 AM Masahiro Yamada <masahiroy@kernel.org> wrote:
>
> These are redundant because -Wall implies
> -Wformat-overflow and -Wformat-truncation
> according to the GCC manual.

To triple check this grouping behavior in clang, there's a utility
called `diagtool`.

$ diagtool tree

will print the hierarchy of diagnostics and color code them to explain
whether they're on/off by default or not-implemented-but-recognized.

For the above two -Wformat-* warnings, note that clang does not yet
implement those.  I've filed
https://github.com/llvm/llvm-project/issues/64871 to track that.
diff mbox series

Patch

diff --git a/scripts/Makefile.extrawarn b/scripts/Makefile.extrawarn
index 87bfe153198f1..ec528972371fa 100644
--- a/scripts/Makefile.extrawarn
+++ b/scripts/Makefile.extrawarn
@@ -16,8 +16,6 @@  KBUILD_CFLAGS += -Werror=strict-prototypes
 KBUILD_CFLAGS += -Wno-format-security
 KBUILD_CFLAGS += -Wno-trigraphs
 KBUILD_CFLAGS += $(call cc-disable-warning,frame-address,)
-KBUILD_CFLAGS += $(call cc-disable-warning, format-truncation)
-KBUILD_CFLAGS += $(call cc-disable-warning, format-overflow)
 KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member)
 
 ifneq ($(CONFIG_FRAME_WARN),0)
@@ -56,9 +54,6 @@  KBUILD_CFLAGS += -Wno-pointer-sign
 # globally built with -Wcast-function-type.
 KBUILD_CFLAGS += $(call cc-option, -Wcast-function-type)
 
-# 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)
 
@@ -111,6 +106,9 @@  KBUILD_CFLAGS += -Wmissing-include-dirs
 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, -Wformat-overflow)
+KBUILD_CFLAGS += $(call cc-option, -Wformat-truncation)
+KBUILD_CFLAGS += $(call cc-option, -Wstringop-overflow)
 KBUILD_CFLAGS += $(call cc-option, -Wstringop-truncation)
 
 KBUILD_CPPFLAGS += -Wundef
@@ -123,6 +121,9 @@  else
 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, format-overflow)
+KBUILD_CFLAGS += $(call cc-disable-warning, format-truncation)
+KBUILD_CFLAGS += $(call cc-disable-warning, stringop-overflow)
 KBUILD_CFLAGS += $(call cc-disable-warning, stringop-truncation)
 
 ifdef CONFIG_CC_IS_CLANG