From: Nathan Chancellor <nathan@kernel.org>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Masahiro Yamada <masahiroy@kernel.org>,
Nicolas Schier <nicolas.schier@linux.dev>,
Nick Desaulniers <nick.desaulniers+lkml@gmail.com>,
Bill Wendling <morbo@google.com>,
Justin Stitt <justinstitt@google.com>,
linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org,
llvm@lists.linux.dev, patches@lists.linux.dev,
stable@vger.kernel.org,
Linux Kernel Functional Testing <lkft@linaro.org>,
Marcus Seyfarth <m.seyfarth@gmail.com>,
Al Viro <viro@zeniv.linux.org.uk>
Subject: Re: [PATCH 2/2] include/linux/typecheck.h: Zero initialize dummy variables
Date: Thu, 1 May 2025 19:09:19 -0700 [thread overview]
Message-ID: <20250502020919.GB1744689@ax162> (raw)
In-Reply-To: <CAHk-=wif4eOpn3YaUXMKUhSrF1t-2ABasBiBRXR2Mxm059yXqQ@mail.gmail.com>
On Thu, May 01, 2025 at 06:34:57PM -0700, Linus Torvalds wrote:
> On Thu, 1 May 2025 at 18:24, Nathan Chancellor <nathan@kernel.org> wrote:
> >
> > but '= {0}' appears to work: https://godbolt.org/z/x7eae5vex
> >
> > If using that instead upsets sparse still, then I can just abandon this
> > change and update the other patch to disable -Wdefault-const-init-unsafe
> > altogether (
>
> The "= { 0 }" form makes sparse unhappy for a different reason:
>
> void *a = { 0 };
>
> makes sparse (correctly) complain about the use of '0' for 'NULL'.
>
> warning: Using plain integer as NULL pointer
>
> and gcc has also finally adopted that warning for braindamage:
>
> warning: zero as null pointer constant [-Wzero-as-null-pointer-constant]
> although it's not on by default (and apparently we've never enabled it
> for the kernel - although we really should).
>
> sparse has complained about this since day one, because I personally
> find the "plain 0 as NULL" to be a complete BS mistake in the language
> (that came from avoiding a keyword, not from some "design" reason),
> and while it took C++ people three decades to figure that out, in the
> end they did indeed figure it out.
Yeah, that is all entirely reasonable. It does not really seem like
there is a clean way to deal with this with our matrix (aside from
something like a local __diag_push() sequence, which I understand you do
not like), so I will abandon this and just turn off the warning entirely
(unless folks have other ideas). I am not really sure we will miss it
because clang will still warn if the variable is used uninitialized
since -Wuninitialized is enabled in -Wall.
$ cat test.c
int main(void)
{
const int a, b;
return a;
}
$ clang -fsyntax-only test.c
test.c:3:15: warning: default initialization of an object of type 'const int' leaves the object uninitialized and is incompatible with C++ [-Wdefault-const-init-var-unsafe]
3 | const int a, b;
| ^
test.c:3:18: warning: default initialization of an object of type 'const int' leaves the object uninitialized and is incompatible with C++ [-Wdefault-const-init-var-unsafe]
3 | const int a, b;
| ^
2 warnings generated.
$ clang -fsyntax-only -Wuninitialized test.c
test.c:3:15: warning: default initialization of an object of type 'const int' leaves the object uninitialized and is incompatible with C++ [-Wdefault-const-init-var-unsafe]
3 | const int a, b;
| ^
test.c:3:18: warning: default initialization of an object of type 'const int' leaves the object uninitialized and is incompatible with C++ [-Wdefault-const-init-var-unsafe]
3 | const int a, b;
| ^
test.c:4:12: warning: variable 'a' is uninitialized when used here [-Wuninitialized]
4 | return a;
| ^
test.c:3:16: note: initialize the variable 'a' to silence this warning
3 | const int a, b;
| ^
| = 0
3 warnings generated.
Cheers,
Nathan
next prev parent reply other threads:[~2025-05-02 2:09 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-01 23:00 [PATCH 0/2] Deal with clang's -Wdefault-const-init-unsafe Nathan Chancellor
2025-05-01 23:00 ` [PATCH 1/2] kbuild: Disable -Wdefault-const-init-field-unsafe Nathan Chancellor
2025-05-09 13:02 ` Masahiro Yamada
2025-05-01 23:00 ` [PATCH 2/2] include/linux/typecheck.h: Zero initialize dummy variables Nathan Chancellor
2025-05-01 23:28 ` Linus Torvalds
2025-05-01 23:37 ` Linus Torvalds
2025-05-02 0:28 ` Al Viro
2025-05-02 1:24 ` Nathan Chancellor
2025-05-02 1:34 ` Linus Torvalds
2025-05-02 2:09 ` Nathan Chancellor [this message]
2025-05-02 2:05 ` Al Viro
2025-05-02 2:36 ` Nathan Chancellor
2025-05-02 9:46 ` kernel test robot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250502020919.GB1744689@ax162 \
--to=nathan@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=justinstitt@google.com \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lkft@linaro.org \
--cc=llvm@lists.linux.dev \
--cc=m.seyfarth@gmail.com \
--cc=masahiroy@kernel.org \
--cc=morbo@google.com \
--cc=nick.desaulniers+lkml@gmail.com \
--cc=nicolas.schier@linux.dev \
--cc=patches@lists.linux.dev \
--cc=stable@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox