Re: [PATCH] perf/x86/amd/uncore: fix error codes in amd_uncore_init()
From: Ingo Molnar
Date: Sat Oct 14 2023 - 05:03:14 EST
* Uros Bizjak <ubizjak@xxxxxxxxx> wrote:
> On Fri, Oct 13, 2023 at 11:06 AM Ingo Molnar <mingo@xxxxxxxxxx> wrote:
> >
> >
> > * Dan Carpenter <dan.carpenter@xxxxxxxxxx> wrote:
> >
> > > On Fri, Oct 13, 2023 at 09:30:46AM +0200, Ingo Molnar wrote:
> > >
> > > > Ugh, why on Earth didn't GCC warn about this? The bad pattern is pretty
> > > > simple & obvious once pointed out ... compilers should have no trouble
> > > > realizing that 'ret' is returned uninitialized in some of these control
> > > > paths. Yet not a peep from the compiler ...
> > >
> > > We disabled that warning years ago (5?) because GCC had too many false
> > > positives.
> >
> > GCC had some pretty bogus notions about 'possible' uninitialized use that
> > encouraged some bad code patterns, but in this case there's readily
> > provable uninitialized use, that a compiler should warn about.
> >
> > Is it possible to disable just the unreliable, probabilistic part of GCC's
> > uninitialized variables warnings?
>
> -Wno-maybe-uninitialized?
No combination of the relevant compiler options appears to be able to get
GCC to notice this bug.
On top of tip:master, the patch below produces no compiler warnings with
GCC 12.3.0:
$ git revert 7543365739a4
$ rm -f arch/x86/events/amd/uncore.o
$ make V=1 W=1e arch/x86/events/amd/uncore.o
The "W=1e" incantation activates, with the patch below applied, among many
other GCC options, the following options:
-Wall
-Wuninitialized
-Wmaybe-uninitialized
-Werror
Which should have found this bug, right?
[ The V=1 helps double checking the compiler options. ]
Thanks,
Ingo
scripts/Makefile.extrawarn | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/scripts/Makefile.extrawarn b/scripts/Makefile.extrawarn
index 2fe6f2828d37..9d245fcff419 100644
--- a/scripts/Makefile.extrawarn
+++ b/scripts/Makefile.extrawarn
@@ -108,6 +108,8 @@ 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_CFLAGS += $(call cc-option, -Wuninitialized)
+KBUILD_CFLAGS += $(call cc-option, -Wmaybe-uninitialized)
KBUILD_CPPFLAGS += -Wundef
KBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN1
@@ -176,7 +178,7 @@ KBUILD_CFLAGS += -Wno-shift-negative-value
ifdef CONFIG_CC_IS_CLANG
KBUILD_CFLAGS += -Wno-initializer-overrides
else
-KBUILD_CFLAGS += -Wno-maybe-uninitialized
+#KBUILD_CFLAGS += -Wno-maybe-uninitialized
endif
endif