From: Nick Desaulniers <ndesaulniers@google.com>
To: Zeng Heng <zengheng4@huawei.com>
Cc: masahiroy@kernel.org, michal.lkml@markovi.net,
akpm@linux-foundation.org, peterz@infradead.org,
keescook@chromium.org, davidgow@google.com, nathan@kernel.org,
jpoimboe@kernel.org, dan.j.williams@intel.com, ojeda@kernel.org,
isabbasso@riseup.net, dmitrii.bundin.a@gmail.com, vbabka@suse.cz,
linux@rasmusvillemoes.dk, linux-kbuild@vger.kernel.org,
linux-kernel@vger.kernel.org, liwei391@huawei.com,
weiyongjun1@huawei.com, clang-built-linux <llvm@lists.linux.dev>,
linux-toolchains <linux-toolchains@vger.kernel.org>
Subject: Re: [PATCH -next] Makefile: add implicit enum-conversion check for compile build
Date: Tue, 27 Sep 2022 09:45:17 -0700 [thread overview]
Message-ID: <CAKwvOdm2r_PPogCecGL4TMeYLq3qNkCbt7zqYTLmQf-PAQMGMg@mail.gmail.com> (raw)
In-Reply-To: <20220927153125.811911-1-zengheng4@huawei.com>
On Tue, Sep 27, 2022 at 8:15 AM Zeng Heng <zengheng4@huawei.com> wrote:
>
> Provide implicit enum-conversion warning option
> in general build. When it set enabled, it can
> detect implicit enum type conversion and find
> potential conversion errors like below
> (use "allmodconfig"):
>
> drivers/gpu/drm/amd/amdgpu/../display/dc/dml/dcn20/display_mode_vba_20.c:3904:46:
> error: implicit conversion from ‘enum <anonymous>’ to ‘enum odm_combine_mode’ [-Werror=enum-conversion]
> 3904 | locals->ODMCombineEnablePerState[i][k] = true;
> | ^
>
> The '-Wenum-conversion' could be regarded as
> effective check on compile runtime and
> call attention on potential mistakes.
>
> Anothor practical example could be referred to:
> https://lore.kernel.org/all/CADnq5_OE0yZvEYGu82QJHL9wvVcTFZrmeTgX7URgh7FVA=jqYg@mail.gmail.com
>
> "-Wenum-conversion" was firstly introduced from
> GNU gcc-10.
What about clang? ;)
>
> Although "-Wenum-conversion" could be enabled
> by "-Wextra" when compiling with 'W=1' option,
> there are many warnings generated by '-Wextra'
> that cause too much noise in a build.
With clang, I believe that -Wenum-conversion is part of -Wall or
-Wextra; so enabling this explicitly is only necessary for GCC. I
wonder why it's not part of -Wall or -Wextra for GCC? Perhaps worth a
bug report/feature request?
>
> Seeing the details from the following link:
> https://gcc.gnu.org/onlinedocs/gcc-11.3.0/gcc/Warning-Options.html
>
> Because there are still some concerned warnings
> exist, the patch marks the option disabled in default
> for avoiding compile failed like using "allmodconfig".
>
> Signed-off-by: Zeng Heng <zengheng4@huawei.com>
> ---
> Makefile | 5 +++++
> lib/Kconfig.debug | 7 +++++++
> 2 files changed, 12 insertions(+)
>
> diff --git a/Makefile b/Makefile
> index ebd48fc956a3..1790a3624358 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -880,6 +880,11 @@ endif
> KBUILD_CFLAGS += $(call cc-disable-warning, unused-but-set-variable)
> KBUILD_CFLAGS += $(call cc-disable-warning, unused-const-variable)
>
> +# check implicit enum conversion
> +ifdef CONFIG_ENUM_CONVERSION
> +KBUILD_CFLAGS += -Wenum-conversion
> +endif
Having a kconfig for this is overkill. cc-option with a comment about
the compiler default versions is the way to go.
> +
> # These result in bogus false positives
> KBUILD_CFLAGS += $(call cc-disable-warning, dangling-pointer)
>
> diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
> index 4f2b81229a2f..a64e06a747d8 100644
> --- a/lib/Kconfig.debug
> +++ b/lib/Kconfig.debug
> @@ -417,6 +417,13 @@ config FRAME_WARN
> Setting this too low will cause a lot of warnings.
> Setting it to 0 disables the warning.
>
> +config ENUM_CONVERSION
> + bool "Warn for implicit enum conversion"
> + depends on GCC_VERSION >= 100300
> + default n
> + help
> + Tell gcc to warn at build time for implicit enum conversion.
> +
> config STRIP_ASM_SYMS
> bool "Strip assembler-generated symbols during link"
> default n
> --
> 2.25.1
>
--
Thanks,
~Nick Desaulniers
next parent reply other threads:[~2022-09-27 16:46 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20220927153125.811911-1-zengheng4@huawei.com>
2022-09-27 16:45 ` Nick Desaulniers [this message]
2022-09-27 17:02 ` [PATCH -next] Makefile: add implicit enum-conversion check for compile build Nathan Chancellor
2022-09-28 7:17 ` Zeng Heng
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=CAKwvOdm2r_PPogCecGL4TMeYLq3qNkCbt7zqYTLmQf-PAQMGMg@mail.gmail.com \
--to=ndesaulniers@google.com \
--cc=akpm@linux-foundation.org \
--cc=dan.j.williams@intel.com \
--cc=davidgow@google.com \
--cc=dmitrii.bundin.a@gmail.com \
--cc=isabbasso@riseup.net \
--cc=jpoimboe@kernel.org \
--cc=keescook@chromium.org \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-toolchains@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=liwei391@huawei.com \
--cc=llvm@lists.linux.dev \
--cc=masahiroy@kernel.org \
--cc=michal.lkml@markovi.net \
--cc=nathan@kernel.org \
--cc=ojeda@kernel.org \
--cc=peterz@infradead.org \
--cc=vbabka@suse.cz \
--cc=weiyongjun1@huawei.com \
--cc=zengheng4@huawei.com \
/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;
as well as URLs for NNTP newsgroup(s).