Linux: Enable -Wuninitialized

Created on 26 Feb 2019  路  14Comments  路  Source: ClangBuiltLinux/linux

29b00e609960ae0fcff382f4c7079dd0874a5311 would have been caught with Clang in its default configuration (and not by GCC due to a bug), as pointed out in this thread: https://lore.kernel.org/lkml/[email protected]/

However, -Wuninitialized also disables -Wsometimes-uninitialized so this was missed by both compilers :(

I am going to test the following diff then send it along right away if there are no additional warnings:

diff --git a/scripts/Makefile.extrawarn b/scripts/Makefile.extrawarn
index 768306add591..f4332981ea85 100644
--- a/scripts/Makefile.extrawarn
+++ b/scripts/Makefile.extrawarn
@@ -72,5 +72,6 @@ KBUILD_CFLAGS += $(call cc-disable-warning, format)
 KBUILD_CFLAGS += $(call cc-disable-warning, sign-compare)
 KBUILD_CFLAGS += $(call cc-disable-warning, format-zero-length)
 KBUILD_CFLAGS += $(call cc-disable-warning, uninitialized)
+KBUILD_CFLAGS += $(call cc-option, -Wsometimes-uninitialized)
 endif
 endif

Side note, looks like this might be a good time to tell Linus about the KernelCI work that is going on: https://lore.kernel.org/lkml/CAHk-=wggjLsi-1BmDHqWAJPzBvTD_-MQNo5qQ9WCuncnyWPROg@mail.gmail.com/

-Wsometimes-uninitialized -Wuninitialized [BUG] linux [FIXED][LINUX] 5.3

Most helpful comment

All 14 comments

heh, wish I was cc'ed on that thread (I'm not subbed to lkml, ducks)

I'm not subbed to lkml, _ducks_

Neither am I, I happened to stumble across it while browsing https://lore.kernel.org/lkml/. Guess I should be after this.

It is still possible to reply without being CC'd (if you use mutt). Otherwise, the link gives reply instructions using git send-email at the bottom.

$ curl -LSs -o mbox https://lore.kernel.org/lkml/CAHk-=wggjLsi-1BmDHqWAJPzBvTD_-MQNo5qQ9WCuncnyWPROg@mail.gmail.com/raw
$ mutt -f mbox

Unfortunately, introduces a few warnings: https://gist.github.com/nathanchance/59f35754366c7d68141a5f44fe9302b8

Another project like #378 (seems like it could be achieved quicker).

Yes; and many of those have the same source file (and even the same warning in some cases; like maybe a shared problematic macro). Thanks for the link; I'll file bugs for all of those, and we'll use this to track enabling the warning.

12 altogether (including this one)

Filed some more issues last night that appeared after I quickly hacked up a monolithic patch to address the ones above. I should have just built without -Werror the first time, sigh.

Still, only 22 instances it looks like, I'll start working on them in a bit.

specifically scripts/Makefile.extrawarn has this block:

ifdef CONFIG_CC_IS_CLANG
KBUILD_CFLAGS += $(call cc-disable-warning, initializer-overrides)
KBUILD_CFLAGS += $(call cc-disable-warning, unused-value)
KBUILD_CFLAGS += $(call cc-disable-warning, format)
KBUILD_CFLAGS += $(call cc-disable-warning, sign-compare)
KBUILD_CFLAGS += $(call cc-disable-warning, format-zero-length)
KBUILD_CFLAGS += $(call cc-disable-warning, uninitialized)
endif

Alright, we are down to three open warnings: #465, #492, and #499.

465's patch has been picked up, ideally it is merged this cycle.

492's patch is pending.

499 has a patch, it just needs to be sent out for review.

It might be worth pulling the trigger and enabling the warnings before these issues are fixed in -next so things like KernelCI and 0day can catch them quicker.

@nathanchance I think it's time to send the patch enabling this. WDYT?

499 and #504 (which has been acked) are the only outstanding warnings. I have been waiting for @arndb to send his patch for #499: https://github.com/nathanchance/patches/blob/71522974ccf011ed721731c14befaae70bf149d2/linux/Wuninitialized/0002-sched-wait-Apply-Arnd-s-__WAIT_QUEUE_HEAD_INIT_ONSTA.patch

I am fine with enabling this now though so we get more coverage on CI.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nathanchance picture nathanchance  路  3Comments

nathanchance picture nathanchance  路  4Comments

nickdesaulniers picture nickdesaulniers  路  4Comments

nickdesaulniers picture nickdesaulniers  路  4Comments

nathanchance picture nathanchance  路  3Comments