From: Nathan Chancellor <nathan@kernel.org>
To: hamjin <jinham@qq.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] lib: typecheck: initialize const variable to avoid Clang warning
Date: Wed, 25 Mar 2026 19:04:48 -0700 [thread overview]
Message-ID: <20260326020448.GA1294592@ax162> (raw)
In-Reply-To: <tencent_274FD06231C70768C2C28FD13673A24C2B08@qq.com>
On Sun, Mar 15, 2026 at 04:52:48PM +0800, hamjin wrote:
> Building the kernel with newer Clang versions triggers
> -Wdefault-const-init-var-unsafe in the typecheck() macro:
>
> error: default initialization of an object of type 'const unsigned long'
> leaves the object uninitialized [-Wdefault-const-init-var-unsafe]
>
> The warning originates from the following declaration in typecheck():
>
> typeof(x) __dummy2;
>
> When 'x' has a const-qualified type (e.g. 'const unsigned long'),
> Clang warns that the variable is declared const but not initialized.
> With -Werror enabled this causes the build to fail.
>
> Initialize the temporary variable to zero to silence the warning:
>
> typeof(x) __dummy2 = (typeof(x))0;
>
> This variable is only used for compile-time type checking and its
> value is never read, so the initialization has no functional impact
> on the generated code.
>
> Fixes: e0deaff47090 ("split the typecheck macros out of include/linux/kernel.h")
> Signed-off-by: hamjin <jinham@qq.com>
> ---
> include/linux/typecheck.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/include/linux/typecheck.h b/include/linux/typecheck.h
> index 46b15e2aaefb..09f280da5b52 100644
> --- a/include/linux/typecheck.h
> +++ b/include/linux/typecheck.h
> @@ -8,7 +8,7 @@
> */
> #define typecheck(type,x) \
> ({ type __dummy; \
> - typeof(x) __dummy2; \
> + typeof(x) __dummy2 = (typeof(x))0; \
> (void)(&__dummy == &__dummy2); \
> 1; \
> })
> --
> 2.53.0
>
As you can see from the build reports, this does not work. Are you
missing commit d0afcfeb9e38 ("kbuild: Disable
-Wdefault-const-init-unsafe") in your tree? Or does this appear in
somewhere that uses its own KBUILD_CFLAGS, in which case a fix like
5ba35a6c13ff ("s390/boot: Add -Wno-default-const-init-unsafe to KBUILD_CFLAGS")
b4780fe4ddf0 ("s390/purgatory: Add -Wno-default-const-init-unsafe to KBUILD_CFLAGS")
will be needed? I do not see any instances of this warning in Linus's
tree unless I am missing some configuration in my build tests.
Cheers,
Nathan
prev parent reply other threads:[~2026-03-26 2:04 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-15 8:52 [PATCH] lib: typecheck: initialize const variable to avoid Clang warning hamjin
2026-03-15 15:12 ` kernel test robot
2026-03-25 12:07 ` kernel test robot
2026-03-25 12:52 ` kernel test robot
2026-03-26 2:04 ` Nathan Chancellor [this message]
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=20260326020448.GA1294592@ax162 \
--to=nathan@kernel.org \
--cc=jinham@qq.com \
--cc=linux-kernel@vger.kernel.org \
/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