2021-08-17 00:58:30

by Nathan Chancellor

[permalink] [raw]
Subject: [PATCH] kbuild: Enable -Wimplicit-fallthrough for clang 14.0.0+

Clang prior to 14.0.0 warns when a fallthrough annotation is in an
unreachable spot, which can occur when IS_ENABLED(CONFIG_...) in a
conditional statement prior to the fallthrough annotation such as

if (IS_ENABLED(CONFIG_...))
break;
fallthrough;

which to clang looks like

break;
fallthrough;

if CONFIG_... is enabled due to the control flow graph. Example of the
warning in practice:

sound/core/pcm_native.c:3812:3: warning: fallthrough annotation in
unreachable code [-Wimplicit-fallthrough]
fallthrough;
^

Warning on unreachable annotations makes the warning too noisy and
pointless for the kernel due to the nature of guarding some code on
configuration options so it was disabled in commit d936eb238744 ("Revert
"Makefile: Enable -Wimplicit-fallthrough for Clang"").

This has been resolved in clang 14.0.0 by moving the unreachable warning
to its own flag under -Wunreachable-code, which the kernel will most
likely never enable due to situations like this.

Enable -Wimplicit-fallthrough for clang 14+ so that issues such as the
one in commit 652b44453ea9 ("habanalabs/gaudi: fix missing code in ECC
handling") can be caught before they enter the tree.

Link: https://github.com/ClangBuiltLinux/linux/issues/236
Link: https://github.com/llvm/llvm-project/commit/9ed4a94d6451046a51ef393cd62f00710820a7e8
Signed-off-by: Nathan Chancellor <[email protected]>
---
Makefile | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index c19d1638da25..91a4a80409e1 100644
--- a/Makefile
+++ b/Makefile
@@ -797,11 +797,17 @@ KBUILD_CFLAGS += -Wno-gnu
# source of a reference will be _MergedGlobals and not on of the whitelisted names.
# See modpost pattern 2
KBUILD_CFLAGS += -mno-global-merge
+
+# Warn about unmarked fall-throughs in switch statement.
+# Clang prior to 14.0.0 warned on unreachable fallthroughs with
+# -Wimplicit-fallthrough, which is unacceptable due to IS_ENABLED().
+# https://bugs.llvm.org/show_bug.cgi?id=51094
+ifeq ($(shell test $(CONFIG_CLANG_VERSION) -ge 140000; echo $$?),0)
+KBUILD_CFLAGS += -Wimplicit-fallthrough
+endif
else

# Warn about unmarked fall-throughs in switch statement.
-# Disabled for clang while comment to attribute conversion happens and
-# https://github.com/ClangBuiltLinux/linux/issues/636 is discussed.
KBUILD_CFLAGS += $(call cc-option,-Wimplicit-fallthrough=5,)
endif


base-commit: a2824f19e6065a0d3735acd9fe7155b104e7edf5
--
2.33.0


2021-08-17 04:17:15

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH] kbuild: Enable -Wimplicit-fallthrough for clang 14.0.0+

Hi Nathan,

I love your patch! Perhaps something to improve:

[auto build test WARNING on a2824f19e6065a0d3735acd9fe7155b104e7edf5]

url: https://github.com/0day-ci/linux/commits/Nathan-Chancellor/kbuild-Enable-Wimplicit-fallthrough-for-clang-14-0-0/20210817-085926
base: a2824f19e6065a0d3735acd9fe7155b104e7edf5
config: mips-randconfig-r003-20210816 (attached as .config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project 2c6448cdc2f68f8c28fd0bd9404182b81306e6e6)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# install mips cross compiling tool for clang build
# apt-get install binutils-mips-linux-gnu
# https://github.com/0day-ci/linux/commit/358205a0573f713b532173c9cf3c9efa052dc9d0
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Nathan-Chancellor/kbuild-Enable-Wimplicit-fallthrough-for-clang-14-0-0/20210817-085926
git checkout 358205a0573f713b532173c9cf3c9efa052dc9d0
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=mips

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <[email protected]>

All warnings (new ones prefixed by >>):

sound/core/pcm_native.c:273:18: warning: variable 'old_mask' set but not used [-Wunused-but-set-variable]
struct snd_mask old_mask;
^
sound/core/pcm_native.c:309:22: warning: variable 'old_interval' set but not used [-Wunused-but-set-variable]
struct snd_interval old_interval;
^
sound/core/pcm_native.c:350:22: warning: variable 'old_interval' set but not used [-Wunused-but-set-variable]
struct snd_interval old_interval;
^
sound/core/pcm_native.c:349:18: warning: variable 'old_mask' set but not used [-Wunused-but-set-variable]
struct snd_mask old_mask;
^
sound/core/pcm_native.c:633:18: warning: variable 'old_mask' set but not used [-Wunused-but-set-variable]
struct snd_mask old_mask;
^
sound/core/pcm_native.c:634:22: warning: variable 'old_interval' set but not used [-Wunused-but-set-variable]
struct snd_interval old_interval;
^
>> sound/core/pcm_native.c:3815:3: warning: fallthrough annotation in unreachable code [-Wimplicit-fallthrough]
fallthrough;
^
include/linux/compiler_attributes.h:210:41: note: expanded from macro 'fallthrough'
# define fallthrough __attribute__((__fallthrough__))
^
sound/core/pcm_native.c:3823:3: warning: fallthrough annotation in unreachable code [-Wimplicit-fallthrough]
fallthrough;
^
include/linux/compiler_attributes.h:210:41: note: expanded from macro 'fallthrough'
# define fallthrough __attribute__((__fallthrough__))
^
8 warnings generated.


vim +3815 sound/core/pcm_native.c

e88e8ae639a490 Takashi Iwai 2006-04-28 3798
^1da177e4c3f41 Linus Torvalds 2005-04-16 3799 static int snd_pcm_mmap(struct file *file, struct vm_area_struct *area)
^1da177e4c3f41 Linus Torvalds 2005-04-16 3800 {
877211f5e1b119 Takashi Iwai 2005-11-17 3801 struct snd_pcm_file * pcm_file;
877211f5e1b119 Takashi Iwai 2005-11-17 3802 struct snd_pcm_substream *substream;
^1da177e4c3f41 Linus Torvalds 2005-04-16 3803 unsigned long offset;
^1da177e4c3f41 Linus Torvalds 2005-04-16 3804
^1da177e4c3f41 Linus Torvalds 2005-04-16 3805 pcm_file = file->private_data;
^1da177e4c3f41 Linus Torvalds 2005-04-16 3806 substream = pcm_file->substream;
7eaa943c8ed8e9 Takashi Iwai 2008-08-08 3807 if (PCM_RUNTIME_CHECK(substream))
7eaa943c8ed8e9 Takashi Iwai 2008-08-08 3808 return -ENXIO;
^1da177e4c3f41 Linus Torvalds 2005-04-16 3809
^1da177e4c3f41 Linus Torvalds 2005-04-16 3810 offset = area->vm_pgoff << PAGE_SHIFT;
^1da177e4c3f41 Linus Torvalds 2005-04-16 3811 switch (offset) {
80fe7430c70859 Arnd Bergmann 2018-04-24 3812 case SNDRV_PCM_MMAP_OFFSET_STATUS_OLD:
80fe7430c70859 Arnd Bergmann 2018-04-24 3813 if (pcm_file->no_compat_mmap || !IS_ENABLED(CONFIG_64BIT))
80fe7430c70859 Arnd Bergmann 2018-04-24 3814 return -ENXIO;
c0dbbdad4e11f8 Gustavo A. R. Silva 2020-07-08 @3815 fallthrough;
80fe7430c70859 Arnd Bergmann 2018-04-24 3816 case SNDRV_PCM_MMAP_OFFSET_STATUS_NEW:
42f945970af9df Takashi Iwai 2017-06-19 3817 if (!pcm_status_mmap_allowed(pcm_file))
^1da177e4c3f41 Linus Torvalds 2005-04-16 3818 return -ENXIO;
^1da177e4c3f41 Linus Torvalds 2005-04-16 3819 return snd_pcm_mmap_status(substream, file, area);
80fe7430c70859 Arnd Bergmann 2018-04-24 3820 case SNDRV_PCM_MMAP_OFFSET_CONTROL_OLD:
80fe7430c70859 Arnd Bergmann 2018-04-24 3821 if (pcm_file->no_compat_mmap || !IS_ENABLED(CONFIG_64BIT))
80fe7430c70859 Arnd Bergmann 2018-04-24 3822 return -ENXIO;
c0dbbdad4e11f8 Gustavo A. R. Silva 2020-07-08 3823 fallthrough;
80fe7430c70859 Arnd Bergmann 2018-04-24 3824 case SNDRV_PCM_MMAP_OFFSET_CONTROL_NEW:
b602aa8eb1a0f5 Takashi Iwai 2017-06-27 3825 if (!pcm_control_mmap_allowed(pcm_file))
^1da177e4c3f41 Linus Torvalds 2005-04-16 3826 return -ENXIO;
^1da177e4c3f41 Linus Torvalds 2005-04-16 3827 return snd_pcm_mmap_control(substream, file, area);
^1da177e4c3f41 Linus Torvalds 2005-04-16 3828 default:
^1da177e4c3f41 Linus Torvalds 2005-04-16 3829 return snd_pcm_mmap_data(substream, file, area);
^1da177e4c3f41 Linus Torvalds 2005-04-16 3830 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 3831 return 0;
^1da177e4c3f41 Linus Torvalds 2005-04-16 3832 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 3833

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]


Attachments:
(No filename) (6.29 kB)
.config.gz (34.02 kB)
Download all attachments

2021-08-17 04:21:27

by Nathan Chancellor

[permalink] [raw]
Subject: Re: [PATCH] kbuild: Enable -Wimplicit-fallthrough for clang 14.0.0+


On 8/16/2021 5:56 PM, Nathan Chancellor wrote:
> Clang prior to 14.0.0 warns when a fallthrough annotation is in an
> unreachable spot, which can occur when IS_ENABLED(CONFIG_...) in a
> conditional statement prior to the fallthrough annotation such as
>
> if (IS_ENABLED(CONFIG_...))
> break;
> fallthrough;
>
> which to clang looks like
>
> break;
> fallthrough;
>
> if CONFIG_... is enabled due to the control flow graph. Example of the
> warning in practice:
>
> sound/core/pcm_native.c:3812:3: warning: fallthrough annotation in
> unreachable code [-Wimplicit-fallthrough]
> fallthrough;
> ^
>
> Warning on unreachable annotations makes the warning too noisy and
> pointless for the kernel due to the nature of guarding some code on
> configuration options so it was disabled in commit d936eb238744 ("Revert
> "Makefile: Enable -Wimplicit-fallthrough for Clang"").
>
> This has been resolved in clang 14.0.0 by moving the unreachable warning
> to its own flag under -Wunreachable-code, which the kernel will most
> likely never enable due to situations like this.
>
> Enable -Wimplicit-fallthrough for clang 14+ so that issues such as the
> one in commit 652b44453ea9 ("habanalabs/gaudi: fix missing code in ECC
> handling") can be caught before they enter the tree.
>
> Link: https://github.com/ClangBuiltLinux/linux/issues/236
> Link: https://github.com/llvm/llvm-project/commit/9ed4a94d6451046a51ef393cd62f00710820a7e8
> Signed-off-by: Nathan Chancellor <[email protected]>
> ---
> Makefile | 10 ++++++++--
> 1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/Makefile b/Makefile
> index c19d1638da25..91a4a80409e1 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -797,11 +797,17 @@ KBUILD_CFLAGS += -Wno-gnu
> # source of a reference will be _MergedGlobals and not on of the whitelisted names.
> # See modpost pattern 2
> KBUILD_CFLAGS += -mno-global-merge
> +
> +# Warn about unmarked fall-throughs in switch statement.
> +# Clang prior to 14.0.0 warned on unreachable fallthroughs with
> +# -Wimplicit-fallthrough, which is unacceptable due to IS_ENABLED().
> +# https://bugs.llvm.org/show_bug.cgi?id=51094
> +ifeq ($(shell test $(CONFIG_CLANG_VERSION) -ge 140000; echo $$?),0)
> +KBUILD_CFLAGS += -Wimplicit-fallthrough
> +endif
> else
>
> # Warn about unmarked fall-throughs in switch statement.
> -# Disabled for clang while comment to attribute conversion happens and
> -# https://github.com/ClangBuiltLinux/linux/issues/636 is discussed.
> KBUILD_CFLAGS += $(call cc-option,-Wimplicit-fallthrough=5,)
> endif
>
>
> base-commit: a2824f19e6065a0d3735acd9fe7155b104e7edf5
>

Please do not apply this patch in its current form, as it does not
properly credit Gustavo for all of the hard work he has done for
enabling this warning.

Additionally, there should be some time for the CI systems to update
their clang-14 builds, as the recent 0day report shows.

Cheers,
Nathan

2021-08-17 04:42:03

by Linus Torvalds

[permalink] [raw]
Subject: Re: [PATCH] kbuild: Enable -Wimplicit-fallthrough for clang 14.0.0+

On Mon, Aug 16, 2021 at 6:20 PM Nathan Chancellor <[email protected]> wrote:
>
> Additionally, there should be some time for the CI systems to update
> their clang-14 builds, as the recent 0day report shows.

What?

No, the 0day report shows that the patch is buggy, and that the

ifeq ($(shell test $(CONFIG_CLANG_VERSION) -ge 140000; echo $$?),0)

clearly doesn't work at all, since the flag is enabled on those
systems with old clang versions.

Alternatively, the test works, but the 140000 version is not enough.

So no. This patch is simply completely wrong, and doesn't fix the
problem with Clang's buggy -Wimplicit-fallthrough flag.

Linus

2021-08-17 04:58:20

by Nathan Chancellor

[permalink] [raw]
Subject: Re: [PATCH] kbuild: Enable -Wimplicit-fallthrough for clang 14.0.0+

On 8/16/2021 9:37 PM, Linus Torvalds wrote:
> On Mon, Aug 16, 2021 at 6:20 PM Nathan Chancellor <[email protected]> wrote:
>>
>> Additionally, there should be some time for the CI systems to update
>> their clang-14 builds, as the recent 0day report shows.
>
> What?
>
> No, the 0day report shows that the patch is buggy, and that the
>
> ifeq ($(shell test $(CONFIG_CLANG_VERSION) -ge 140000; echo $$?),0)
>
> clearly doesn't work at all, since the flag is enabled on those
> systems with old clang versions.
>
> Alternatively, the test works, but the 140000 version is not enough.

So technically speaking, the 140000 is not enough at this very moment
for the fact that there are certain systems that test with clang-14
builds that do not have my clang patch in it yet; however, those systems
do update clang regularly (the 0day version is just seven hours old at
the time of writing this) so they will have a version that contains my
patch shortly, making the check work just fine. We have done this in the
past with checks that are gated on clang versions that are in
development, with the expectation that if someone is using a development
release of clang, they are keeping it up to date so that they get fixes
that we push there; otherwise, it is just better to stick with the
release branches.

> So no. This patch is simply completely wrong, and doesn't fix the
> problem with Clang's buggy -Wimplicit-fallthrough flag.

If you/Gustavo would prefer, I can upgrade that check to

ifneq ($(call cc-option, -Wunreachable-code-fallthrough),)

I was just trying to save a call to the compiler, as that is more
expensive than a shell test call.

Cheers,
Nathan

2021-08-17 18:05:18

by Kees Cook

[permalink] [raw]
Subject: Re: [PATCH] kbuild: Enable -Wimplicit-fallthrough for clang 14.0.0+

On Mon, Aug 16, 2021 at 09:55:28PM -0700, Nathan Chancellor wrote:
> If you/Gustavo would prefer, I can upgrade that check to
>
> ifneq ($(call cc-option, -Wunreachable-code-fallthrough),)
>
> I was just trying to save a call to the compiler, as that is more expensive
> than a shell test call.

I prefer the option test -- this means no changes are needed on the
kernel build side if it ever finds itself backported to earlier versions
(and it handles the current case of "14" not meaning "absolute latest").

More specifically, I think you want this (untested):

diff --git a/Makefile b/Makefile
index b5fd51e68ae9..9845ea50a368 100644
--- a/Makefile
+++ b/Makefile
@@ -859,11 +859,11 @@ KBUILD_CFLAGS += -Wno-gnu
# source of a reference will be _MergedGlobals and not on of the whitelisted names.
# See modpost pattern 2
KBUILD_CFLAGS += -mno-global-merge
+# Warn about unmarked fall-throughs in switch statement only if we can also
+# disable the bogus unreachable code warnings.
+KBUILD_CFLAGS += $(call cc-option,-Wimplicit-fallthrough -Wno-unreachable-code-fallthrough,)
else
-
# Warn about unmarked fall-throughs in switch statement.
-# Disabled for clang while comment to attribute conversion happens and
-# https://github.com/ClangBuiltLinux/linux/issues/636 is discussed.
KBUILD_CFLAGS += $(call cc-option,-Wimplicit-fallthrough=5,)
endif


--
Kees Cook

2021-08-17 18:29:51

by Nathan Chancellor

[permalink] [raw]
Subject: Re: [PATCH] kbuild: Enable -Wimplicit-fallthrough for clang 14.0.0+

On 8/17/2021 11:03 AM, Kees Cook wrote:
> On Mon, Aug 16, 2021 at 09:55:28PM -0700, Nathan Chancellor wrote:
>> If you/Gustavo would prefer, I can upgrade that check to
>>
>> ifneq ($(call cc-option, -Wunreachable-code-fallthrough),)
>>
>> I was just trying to save a call to the compiler, as that is more expensive
>> than a shell test call.
>
> I prefer the option test -- this means no changes are needed on the
> kernel build side if it ever finds itself backported to earlier versions
> (and it handles the current case of "14" not meaning "absolute latest").
>
> More specifically, I think you want this (untested):

That should work but since -Wunreachable-code-fallthrough is off by
default, I did not really see a reason to include it in KBUILD_CFLAGS. I
do not have a strong opinion though, your version is smaller than mine
is so we can just go with that. I'll defer to Gustavo on it since he has
put in all of the work cleaning up the warnings.

Cheers,
Nathan

> diff --git a/Makefile b/Makefile
> index b5fd51e68ae9..9845ea50a368 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -859,11 +859,11 @@ KBUILD_CFLAGS += -Wno-gnu
> # source of a reference will be _MergedGlobals and not on of the whitelisted names.
> # See modpost pattern 2
> KBUILD_CFLAGS += -mno-global-merge
> +# Warn about unmarked fall-throughs in switch statement only if we can also
> +# disable the bogus unreachable code warnings.
> +KBUILD_CFLAGS += $(call cc-option,-Wimplicit-fallthrough -Wno-unreachable-code-fallthrough,)
> else
> -
> # Warn about unmarked fall-throughs in switch statement.
> -# Disabled for clang while comment to attribute conversion happens and
> -# https://github.com/ClangBuiltLinux/linux/issues/636 is discussed.
> KBUILD_CFLAGS += $(call cc-option,-Wimplicit-fallthrough=5,)
> endif
>
>

2021-08-17 21:21:16

by Masahiro Yamada

[permalink] [raw]
Subject: Re: [PATCH] kbuild: Enable -Wimplicit-fallthrough for clang 14.0.0+

On Wed, Aug 18, 2021 at 3:25 AM Nathan Chancellor <[email protected]> wrote:
>
> On 8/17/2021 11:03 AM, Kees Cook wrote:
> > On Mon, Aug 16, 2021 at 09:55:28PM -0700, Nathan Chancellor wrote:
> >> If you/Gustavo would prefer, I can upgrade that check to
> >>
> >> ifneq ($(call cc-option, -Wunreachable-code-fallthrough),)
> >>
> >> I was just trying to save a call to the compiler, as that is more expensive
> >> than a shell test call.
> >
> > I prefer the option test -- this means no changes are needed on the
> > kernel build side if it ever finds itself backported to earlier versions
> > (and it handles the current case of "14" not meaning "absolute latest").
> >
> > More specifically, I think you want this (untested):
>
> That should work but since -Wunreachable-code-fallthrough is off by
> default, I did not really see a reason to include it in KBUILD_CFLAGS. I
> do not have a strong opinion though, your version is smaller than mine
> is so we can just go with that. I'll defer to Gustavo on it since he has
> put in all of the work cleaning up the warnings.



https://github.com/llvm/llvm-project/commit/9ed4a94d6451046a51ef393cd62f00710820a7e8

did two things:

(1) Change the -Wimplicit-fallthrough behavior so that it fits
to our use in the kernel

(2) Add a new option -Wunreachable-code-fallthrough
that works like the previous -Wimplicit-fallthrough of
Clang <= 13.0.0


They are separate things.

Checking the presence of -Wunreachable-code-fallthrough
does not make sense since we are only interested in (1) here.



So, checking the Clang version is sensible and matches
the explanation in the comment block.


Moreover, using $(shell test ...) is less expensive than cc-option.


If you want to make it even faster, you can use only
built-in functions, like this:


# Warn about unmarked fall-throughs in switch statement.
# Clang prior to 14.0.0 warned on unreachable fallthroughs with
# -Wimplicit-fallthrough, which is unacceptable due to IS_ENABLED().
# https://bugs.llvm.org/show_bug.cgi?id=51094
ifeq ($(firstword $(sort $(CONFIG_CLANG_VERSION) 140000)),140000)
KBUILD_CFLAGS += -Wimplicit-fallthrough
endif



The $(sort ...) is alphabetical sort, not numeric sort.
It works for us because the minimum Clang version is 10.0.1
(that is CONFIG_CLANG_VERSION is always 6-digit)

It will break when Clang version 100.0.0 is released.

But, before that, we will raise the minimum supported clang version,
and this conditional will go away.




> Cheers,
> Nathan
>
> > diff --git a/Makefile b/Makefile
> > index b5fd51e68ae9..9845ea50a368 100644
> > --- a/Makefile
> > +++ b/Makefile
> > @@ -859,11 +859,11 @@ KBUILD_CFLAGS += -Wno-gnu
> > # source of a reference will be _MergedGlobals and not on of the whitelisted names.
> > # See modpost pattern 2
> > KBUILD_CFLAGS += -mno-global-merge
> > +# Warn about unmarked fall-throughs in switch statement only if we can also
> > +# disable the bogus unreachable code warnings.
> > +KBUILD_CFLAGS += $(call cc-option,-Wimplicit-fallthrough -Wno-unreachable-code-fallthrough,)
> > else
> > -
> > # Warn about unmarked fall-throughs in switch statement.
> > -# Disabled for clang while comment to attribute conversion happens and
> > -# https://github.com/ClangBuiltLinux/linux/issues/636 is discussed.
> > KBUILD_CFLAGS += $(call cc-option,-Wimplicit-fallthrough=5,)
> > endif
> >
> >



--
Best Regards
Masahiro Yamada

2021-08-17 21:34:24

by Gustavo A. R. Silva

[permalink] [raw]
Subject: Re: [PATCH] kbuild: Enable -Wimplicit-fallthrough for clang 14.0.0+



On 8/17/21 16:17, Masahiro Yamada wrote:
> On Wed, Aug 18, 2021 at 3:25 AM Nathan Chancellor <[email protected]> wrote:
>>
>> On 8/17/2021 11:03 AM, Kees Cook wrote:
>>> On Mon, Aug 16, 2021 at 09:55:28PM -0700, Nathan Chancellor wrote:
>>>> If you/Gustavo would prefer, I can upgrade that check to
>>>>
>>>> ifneq ($(call cc-option, -Wunreachable-code-fallthrough),)
>>>>
>>>> I was just trying to save a call to the compiler, as that is more expensive
>>>> than a shell test call.
>>>
>>> I prefer the option test -- this means no changes are needed on the
>>> kernel build side if it ever finds itself backported to earlier versions
>>> (and it handles the current case of "14" not meaning "absolute latest").
>>>
>>> More specifically, I think you want this (untested):
>>
>> That should work but since -Wunreachable-code-fallthrough is off by
>> default, I did not really see a reason to include it in KBUILD_CFLAGS. I
>> do not have a strong opinion though, your version is smaller than mine
>> is so we can just go with that. I'll defer to Gustavo on it since he has
>> put in all of the work cleaning up the warnings.
>
>
>
> https://github.com/llvm/llvm-project/commit/9ed4a94d6451046a51ef393cd62f00710820a7e8
>
> did two things:
>
> (1) Change the -Wimplicit-fallthrough behavior so that it fits
> to our use in the kernel
>
> (2) Add a new option -Wunreachable-code-fallthrough
> that works like the previous -Wimplicit-fallthrough of
> Clang <= 13.0.0
>
>
> They are separate things.
>
> Checking the presence of -Wunreachable-code-fallthrough
> does not make sense since we are only interested in (1) here.
>
>
>
> So, checking the Clang version is sensible and matches
> the explanation in the comment block.
>
>
> Moreover, using $(shell test ...) is less expensive than cc-option.
>
>
> If you want to make it even faster, you can use only
> built-in functions, like this:
>
>
> # Warn about unmarked fall-throughs in switch statement.
> # Clang prior to 14.0.0 warned on unreachable fallthroughs with
> # -Wimplicit-fallthrough, which is unacceptable due to IS_ENABLED().
> # https://bugs.llvm.org/show_bug.cgi?id=51094
> ifeq ($(firstword $(sort $(CONFIG_CLANG_VERSION) 140000)),140000)
> KBUILD_CFLAGS += -Wimplicit-fallthrough
> endif
>
>
>
> The $(sort ...) is alphabetical sort, not numeric sort.
> It works for us because the minimum Clang version is 10.0.1
> (that is CONFIG_CLANG_VERSION is always 6-digit)
>
> It will break when Clang version 100.0.0 is released.
>
> But, before that, we will raise the minimum supported clang version,
> and this conditional will go away.

I like this. :)

I'm going to make the 0-day robot test it in my tree, first.

Thanks!
--
Gustavo


2021-08-17 23:07:30

by Kees Cook

[permalink] [raw]
Subject: Re: [PATCH] kbuild: Enable -Wimplicit-fallthrough for clang 14.0.0+

On Tue, Aug 17, 2021 at 04:33:25PM -0500, Gustavo A. R. Silva wrote:
>
>
> On 8/17/21 16:17, Masahiro Yamada wrote:
> > On Wed, Aug 18, 2021 at 3:25 AM Nathan Chancellor <[email protected]> wrote:
> >>
> >> On 8/17/2021 11:03 AM, Kees Cook wrote:
> >>> On Mon, Aug 16, 2021 at 09:55:28PM -0700, Nathan Chancellor wrote:
> >>>> If you/Gustavo would prefer, I can upgrade that check to
> >>>>
> >>>> ifneq ($(call cc-option, -Wunreachable-code-fallthrough),)
> >>>>
> >>>> I was just trying to save a call to the compiler, as that is more expensive
> >>>> than a shell test call.
> >>>
> >>> I prefer the option test -- this means no changes are needed on the
> >>> kernel build side if it ever finds itself backported to earlier versions
> >>> (and it handles the current case of "14" not meaning "absolute latest").
> >>>
> >>> More specifically, I think you want this (untested):
> >>
> >> That should work but since -Wunreachable-code-fallthrough is off by
> >> default, I did not really see a reason to include it in KBUILD_CFLAGS. I
> >> do not have a strong opinion though, your version is smaller than mine
> >> is so we can just go with that. I'll defer to Gustavo on it since he has
> >> put in all of the work cleaning up the warnings.
> >
> >
> >
> > https://github.com/llvm/llvm-project/commit/9ed4a94d6451046a51ef393cd62f00710820a7e8
> >
> > did two things:
> >
> > (1) Change the -Wimplicit-fallthrough behavior so that it fits
> > to our use in the kernel
> >
> > (2) Add a new option -Wunreachable-code-fallthrough
> > that works like the previous -Wimplicit-fallthrough of
> > Clang <= 13.0.0
> >
> >
> > They are separate things.
> >
> > Checking the presence of -Wunreachable-code-fallthrough
> > does not make sense since we are only interested in (1) here.
> >
> > So, checking the Clang version is sensible and matches
> > the explanation in the comment block.

I thought one of the problems (which is quickly draining away) that
needed to be solved here is that some Clang trunk builds (that report
as version 14) don't yet have support for -Wunreachable-code-fallthrough
since they aren't new enough.

> > # Warn about unmarked fall-throughs in switch statement.
> > # Clang prior to 14.0.0 warned on unreachable fallthroughs with
> > # -Wimplicit-fallthrough, which is unacceptable due to IS_ENABLED().
> > # https://bugs.llvm.org/show_bug.cgi?id=51094
> > ifeq ($(firstword $(sort $(CONFIG_CLANG_VERSION) 140000)),140000)
> > KBUILD_CFLAGS += -Wimplicit-fallthrough
> > endif
> >
> > The $(sort ...) is alphabetical sort, not numeric sort.
> > It works for us because the minimum Clang version is 10.0.1
> > (that is CONFIG_CLANG_VERSION is always 6-digit)
> >
> > It will break when Clang version 100.0.0 is released.
> >
> > But, before that, we will raise the minimum supported clang version,
> > and this conditional will go away.

If a version test is preferred, cool; this is a nice trick. :)

> I like this. :)
>
> I'm going to make the 0-day robot test it in my tree, first.

Sounds good to me!

--
Kees Cook

2021-08-17 23:24:49

by Nathan Chancellor

[permalink] [raw]
Subject: Re: [PATCH] kbuild: Enable -Wimplicit-fallthrough for clang 14.0.0+

On 8/17/2021 4:06 PM, Kees Cook wrote:
> On Tue, Aug 17, 2021 at 04:33:25PM -0500, Gustavo A. R. Silva wrote:
>>
>>
>> On 8/17/21 16:17, Masahiro Yamada wrote:
>>> On Wed, Aug 18, 2021 at 3:25 AM Nathan Chancellor <[email protected]> wrote:
>>>>
>>>> On 8/17/2021 11:03 AM, Kees Cook wrote:
>>>>> On Mon, Aug 16, 2021 at 09:55:28PM -0700, Nathan Chancellor wrote:
>>>>>> If you/Gustavo would prefer, I can upgrade that check to
>>>>>>
>>>>>> ifneq ($(call cc-option, -Wunreachable-code-fallthrough),)
>>>>>>
>>>>>> I was just trying to save a call to the compiler, as that is more expensive
>>>>>> than a shell test call.
>>>>>
>>>>> I prefer the option test -- this means no changes are needed on the
>>>>> kernel build side if it ever finds itself backported to earlier versions
>>>>> (and it handles the current case of "14" not meaning "absolute latest").
>>>>>
>>>>> More specifically, I think you want this (untested):
>>>>
>>>> That should work but since -Wunreachable-code-fallthrough is off by
>>>> default, I did not really see a reason to include it in KBUILD_CFLAGS. I
>>>> do not have a strong opinion though, your version is smaller than mine
>>>> is so we can just go with that. I'll defer to Gustavo on it since he has
>>>> put in all of the work cleaning up the warnings.
>>>
>>>
>>>
>>> https://github.com/llvm/llvm-project/commit/9ed4a94d6451046a51ef393cd62f00710820a7e8
>>>
>>> did two things:
>>>
>>> (1) Change the -Wimplicit-fallthrough behavior so that it fits
>>> to our use in the kernel
>>>
>>> (2) Add a new option -Wunreachable-code-fallthrough
>>> that works like the previous -Wimplicit-fallthrough of
>>> Clang <= 13.0.0
>>>
>>>
>>> They are separate things.
>>>
>>> Checking the presence of -Wunreachable-code-fallthrough
>>> does not make sense since we are only interested in (1) here.
>>>
>>> So, checking the Clang version is sensible and matches
>>> the explanation in the comment block.
>
> I thought one of the problems (which is quickly draining away) that
> needed to be solved here is that some Clang trunk builds (that report
> as version 14) don't yet have support for -Wunreachable-code-fallthrough
> since they aren't new enough.

Philip, how often is the kernel test robot's clang version rebuilt?
Would it be possible to bump it to latest ToT or at least
9ed4a94d6451046a51ef393cd62f00710820a7e8 so that we do not get bit by
this warning when we go to enable this flag?

I do not know of any other CI aside from ours that is testing with tip
of tree clang and ours should already have a clang that includes my
patch since it comes from apt.llvm.org.

>>> # Warn about unmarked fall-throughs in switch statement.
>>> # Clang prior to 14.0.0 warned on unreachable fallthroughs with
>>> # -Wimplicit-fallthrough, which is unacceptable due to IS_ENABLED().
>>> # https://bugs.llvm.org/show_bug.cgi?id=51094
>>> ifeq ($(firstword $(sort $(CONFIG_CLANG_VERSION) 140000)),140000)
>>> KBUILD_CFLAGS += -Wimplicit-fallthrough
>>> endif

Very clever and nifty trick! I have verified that it works for clang 13
and 14 along with a theoretical clang 15. Gustavo, feel free to stick a

Reviewed-by: Nathan Chancellor <[email protected]>
Tested-by: Nathan Chancellor <[email protected]>

if you so desire.

>>>
>>> The $(sort ...) is alphabetical sort, not numeric sort.
>>> It works for us because the minimum Clang version is 10.0.1
>>> (that is CONFIG_CLANG_VERSION is always 6-digit)
>>>
>>> It will break when Clang version 100.0.0 is released.
>>>
>>> But, before that, we will raise the minimum supported clang version,
>>> and this conditional will go away.
>
> If a version test is preferred, cool; this is a nice trick. :)
>
>> I like this. :)
>>
>> I'm going to make the 0-day robot test it in my tree, first.
>
> Sounds good to me!
>

2021-08-17 23:58:59

by Gustavo A. R. Silva

[permalink] [raw]
Subject: Re: [PATCH] kbuild: Enable -Wimplicit-fallthrough for clang 14.0.0+



On 8/17/21 18:23, Nathan Chancellor wrote:
>>>> # Warn about unmarked fall-throughs in switch statement.
>>>> # Clang prior to 14.0.0 warned on unreachable fallthroughs with
>>>> # -Wimplicit-fallthrough, which is unacceptable due to IS_ENABLED().
>>>> # https://bugs.llvm.org/show_bug.cgi?id=51094
>>>> ifeq ($(firstword $(sort $(CONFIG_CLANG_VERSION) 140000)),140000)
>>>> KBUILD_CFLAGS += -Wimplicit-fallthrough
>>>> endif
>
> Very clever and nifty trick! I have verified that it works for clang 13 and 14 along with a theoretical clang 15. Gustavo, feel free to stick a
>
> Reviewed-by: Nathan Chancellor <[email protected]>
> Tested-by: Nathan Chancellor <[email protected]>
>
> if you so desire.

Yep; I just tested it locally with clang 13 and 14, too.

Thanks
--
Gustavo


2021-08-18 04:20:38

by Masahiro Yamada

[permalink] [raw]
Subject: Re: [PATCH] kbuild: Enable -Wimplicit-fallthrough for clang 14.0.0+

On Wed, Aug 18, 2021 at 8:23 AM Nathan Chancellor <[email protected]> wrote:
>
> On 8/17/2021 4:06 PM, Kees Cook wrote:
> > On Tue, Aug 17, 2021 at 04:33:25PM -0500, Gustavo A. R. Silva wrote:
> >>
> >>
> >> On 8/17/21 16:17, Masahiro Yamada wrote:
> >>> On Wed, Aug 18, 2021 at 3:25 AM Nathan Chancellor <[email protected]> wrote:
> >>>>
> >>>> On 8/17/2021 11:03 AM, Kees Cook wrote:
> >>>>> On Mon, Aug 16, 2021 at 09:55:28PM -0700, Nathan Chancellor wrote:
> >>>>>> If you/Gustavo would prefer, I can upgrade that check to
> >>>>>>
> >>>>>> ifneq ($(call cc-option, -Wunreachable-code-fallthrough),)
> >>>>>>
> >>>>>> I was just trying to save a call to the compiler, as that is more expensive
> >>>>>> than a shell test call.
> >>>>>
> >>>>> I prefer the option test -- this means no changes are needed on the
> >>>>> kernel build side if it ever finds itself backported to earlier versions
> >>>>> (and it handles the current case of "14" not meaning "absolute latest").
> >>>>>
> >>>>> More specifically, I think you want this (untested):
> >>>>
> >>>> That should work but since -Wunreachable-code-fallthrough is off by
> >>>> default, I did not really see a reason to include it in KBUILD_CFLAGS. I
> >>>> do not have a strong opinion though, your version is smaller than mine
> >>>> is so we can just go with that. I'll defer to Gustavo on it since he has
> >>>> put in all of the work cleaning up the warnings.
> >>>
> >>>
> >>>
> >>> https://github.com/llvm/llvm-project/commit/9ed4a94d6451046a51ef393cd62f00710820a7e8
> >>>
> >>> did two things:
> >>>
> >>> (1) Change the -Wimplicit-fallthrough behavior so that it fits
> >>> to our use in the kernel
> >>>
> >>> (2) Add a new option -Wunreachable-code-fallthrough
> >>> that works like the previous -Wimplicit-fallthrough of
> >>> Clang <= 13.0.0
> >>>
> >>>
> >>> They are separate things.
> >>>
> >>> Checking the presence of -Wunreachable-code-fallthrough
> >>> does not make sense since we are only interested in (1) here.
> >>>
> >>> So, checking the Clang version is sensible and matches
> >>> the explanation in the comment block.
> >
> > I thought one of the problems (which is quickly draining away) that
> > needed to be solved here is that some Clang trunk builds (that report
> > as version 14) don't yet have support for -Wunreachable-code-fallthrough
> > since they aren't new enough.
>
> Philip, how often is the kernel test robot's clang version rebuilt?
> Would it be possible to bump it to latest ToT or at least
> 9ed4a94d6451046a51ef393cd62f00710820a7e8 so that we do not get bit by
> this warning when we go to enable this flag?
>
> I do not know of any other CI aside from ours that is testing with tip
> of tree clang and ours should already have a clang that includes my
> patch since it comes from apt.llvm.org.
>
> >>> # Warn about unmarked fall-throughs in switch statement.
> >>> # Clang prior to 14.0.0 warned on unreachable fallthroughs with
> >>> # -Wimplicit-fallthrough, which is unacceptable due to IS_ENABLED().
> >>> # https://bugs.llvm.org/show_bug.cgi?id=51094
> >>> ifeq ($(firstword $(sort $(CONFIG_CLANG_VERSION) 140000)),140000)
> >>> KBUILD_CFLAGS += -Wimplicit-fallthrough
> >>> endif
>
> Very clever and nifty trick! I have verified that it works for clang 13
> and 14 along with a theoretical clang 15. Gustavo, feel free to stick a


I am not the inventor of this code, though :-)

I mimicked the code in Buildroot:
https://github.com/buildroot/buildroot/blob/2021.05/Makefile#L104





--
Best Regards
Masahiro Yamada

2021-08-18 04:35:57

by Philip Li

[permalink] [raw]
Subject: Re: [PATCH] kbuild: Enable -Wimplicit-fallthrough for clang 14.0.0+

On Tue, Aug 17, 2021 at 04:23:41PM -0700, Nathan Chancellor wrote:
> On 8/17/2021 4:06 PM, Kees Cook wrote:
> > On Tue, Aug 17, 2021 at 04:33:25PM -0500, Gustavo A. R. Silva wrote:
> > >
> > >
> > > On 8/17/21 16:17, Masahiro Yamada wrote:
> > > > On Wed, Aug 18, 2021 at 3:25 AM Nathan Chancellor <[email protected]> wrote:
> > > > >
> > > > > On 8/17/2021 11:03 AM, Kees Cook wrote:
> > > > > > On Mon, Aug 16, 2021 at 09:55:28PM -0700, Nathan Chancellor wrote:
> > > > > > > If you/Gustavo would prefer, I can upgrade that check to
> > > > > > >
> > > > > > > ifneq ($(call cc-option, -Wunreachable-code-fallthrough),)
> > > > > > >
> > > > > > > I was just trying to save a call to the compiler, as that is more expensive
> > > > > > > than a shell test call.
> > > > > >
> > > > > > I prefer the option test -- this means no changes are needed on the
> > > > > > kernel build side if it ever finds itself backported to earlier versions
> > > > > > (and it handles the current case of "14" not meaning "absolute latest").
> > > > > >
> > > > > > More specifically, I think you want this (untested):
> > > > >
> > > > > That should work but since -Wunreachable-code-fallthrough is off by
> > > > > default, I did not really see a reason to include it in KBUILD_CFLAGS. I
> > > > > do not have a strong opinion though, your version is smaller than mine
> > > > > is so we can just go with that. I'll defer to Gustavo on it since he has
> > > > > put in all of the work cleaning up the warnings.
> > > >
> > > >
> > > >
> > > > https://github.com/llvm/llvm-project/commit/9ed4a94d6451046a51ef393cd62f00710820a7e8
> > > >
> > > > did two things:
> > > >
> > > > (1) Change the -Wimplicit-fallthrough behavior so that it fits
> > > > to our use in the kernel
> > > >
> > > > (2) Add a new option -Wunreachable-code-fallthrough
> > > > that works like the previous -Wimplicit-fallthrough of
> > > > Clang <= 13.0.0
> > > >
> > > >
> > > > They are separate things.
> > > >
> > > > Checking the presence of -Wunreachable-code-fallthrough
> > > > does not make sense since we are only interested in (1) here.
> > > >
> > > > So, checking the Clang version is sensible and matches
> > > > the explanation in the comment block.
> >
> > I thought one of the problems (which is quickly draining away) that
> > needed to be solved here is that some Clang trunk builds (that report
> > as version 14) don't yet have support for -Wunreachable-code-fallthrough
> > since they aren't new enough.
>
> Philip, how often is the kernel test robot's clang version rebuilt? Would it
> be possible to bump it to latest ToT or at least
> 9ed4a94d6451046a51ef393cd62f00710820a7e8 so that we do not get bit by this
> warning when we go to enable this flag?
Got it, currently we do upgrade in weekly cadence (but it may fall behind sometimes),
and the one we use now is clang version 14.0.0 (https://github.com/llvm/llvm-project
2c6448cdc2f68f8c28fd0bd9404182b81306e6e6)

We will ugrade to the head of llvm-project master today.

Thanks

>
> I do not know of any other CI aside from ours that is testing with tip of
> tree clang and ours should already have a clang that includes my patch since
> it comes from apt.llvm.org.
>
> > > > # Warn about unmarked fall-throughs in switch statement.
> > > > # Clang prior to 14.0.0 warned on unreachable fallthroughs with
> > > > # -Wimplicit-fallthrough, which is unacceptable due to IS_ENABLED().
> > > > # https://bugs.llvm.org/show_bug.cgi?id=51094
> > > > ifeq ($(firstword $(sort $(CONFIG_CLANG_VERSION) 140000)),140000)
> > > > KBUILD_CFLAGS += -Wimplicit-fallthrough
> > > > endif
>
> Very clever and nifty trick! I have verified that it works for clang 13 and
> 14 along with a theoretical clang 15. Gustavo, feel free to stick a
>
> Reviewed-by: Nathan Chancellor <[email protected]>
> Tested-by: Nathan Chancellor <[email protected]>
>
> if you so desire.
>
> > > >
> > > > The $(sort ...) is alphabetical sort, not numeric sort.
> > > > It works for us because the minimum Clang version is 10.0.1
> > > > (that is CONFIG_CLANG_VERSION is always 6-digit)
> > > >
> > > > It will break when Clang version 100.0.0 is released.
> > > >
> > > > But, before that, we will raise the minimum supported clang version,
> > > > and this conditional will go away.
> >
> > If a version test is preferred, cool; this is a nice trick. :)
> >
> > > I like this. :)
> > >
> > > I'm going to make the 0-day robot test it in my tree, first.
> >
> > Sounds good to me!
> >

2021-08-18 04:45:06

by Gustavo A. R. Silva

[permalink] [raw]
Subject: Re: [PATCH] kbuild: Enable -Wimplicit-fallthrough for clang 14.0.0+



On 8/17/21 23:27, Philip Li wrote:

>> Philip, how often is the kernel test robot's clang version rebuilt? Would it
>> be possible to bump it to latest ToT or at least
>> 9ed4a94d6451046a51ef393cd62f00710820a7e8 so that we do not get bit by this
>> warning when we go to enable this flag?
> Got it, currently we do upgrade in weekly cadence (but it may fall behind sometimes),
> and the one we use now is clang version 14.0.0 (https://github.com/llvm/llvm-project
> 2c6448cdc2f68f8c28fd0bd9404182b81306e6e6)
>
> We will ugrade to the head of llvm-project master today.

Thanks, Philip. We really appreciate it.
--
Gustavo

2021-08-18 07:38:15

by Philip Li

[permalink] [raw]
Subject: Re: [PATCH] kbuild: Enable -Wimplicit-fallthrough for clang 14.0.0+

On Tue, Aug 17, 2021 at 11:45:48PM -0500, Gustavo A. R. Silva wrote:
>
>
> On 8/17/21 23:27, Philip Li wrote:
>
> >> Philip, how often is the kernel test robot's clang version rebuilt? Would it
> >> be possible to bump it to latest ToT or at least
> >> 9ed4a94d6451046a51ef393cd62f00710820a7e8 so that we do not get bit by this
> >> warning when we go to enable this flag?
> > Got it, currently we do upgrade in weekly cadence (but it may fall behind sometimes),
> > and the one we use now is clang version 14.0.0 (https://github.com/llvm/llvm-project
> > 2c6448cdc2f68f8c28fd0bd9404182b81306e6e6)
> >
> > We will ugrade to the head of llvm-project master today.
>
> Thanks, Philip. We really appreciate it.
you are welcome. Per the upgrade in this noon. Now we start to use below commit to
do further clang build test (which is after the required 9ed4a94d6451)

commit d2b574a4dea5b718e4386bf2e26af0126e5978ce
Author: Marco Elver <[email protected]>
Date: Tue Aug 17 16:54:07 2021 +0200

tsan: test: Initialize all fields of Params struct

Thanks

> --
> Gustavo

2021-08-18 12:14:47

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH] kbuild: Enable -Wimplicit-fallthrough for clang 14.0.0+

On Tue, Aug 17, 2021 at 04:23:41PM -0700, Nathan Chancellor wrote:

> I do not know of any other CI aside from ours that is testing with tip of
> tree clang and ours should already have a clang that includes my patch since
> it comes from apt.llvm.org.

FWIW we have some testing internally at Arm but that's building from
source so it's not an issue for us.


Attachments:
(No filename) (367.00 B)
signature.asc (499.00 B)
Download all attachments

2021-08-25 21:15:58

by Nick Desaulniers

[permalink] [raw]
Subject: Re: [PATCH] kbuild: Enable -Wimplicit-fallthrough for clang 14.0.0+

On Tue, Aug 17, 2021 at 2:18 PM Masahiro Yamada <[email protected]> wrote:
>
> On Wed, Aug 18, 2021 at 3:25 AM Nathan Chancellor <[email protected]> wrote:
> >
> > On 8/17/2021 11:03 AM, Kees Cook wrote:
> > > On Mon, Aug 16, 2021 at 09:55:28PM -0700, Nathan Chancellor wrote:
> > >> If you/Gustavo would prefer, I can upgrade that check to
> > >>
> > >> ifneq ($(call cc-option, -Wunreachable-code-fallthrough),)
> > >>
> > >> I was just trying to save a call to the compiler, as that is more expensive
> > >> than a shell test call.
> > >
> > > I prefer the option test -- this means no changes are needed on the
> > > kernel build side if it ever finds itself backported to earlier versions
> > > (and it handles the current case of "14" not meaning "absolute latest").
> > >
> > > More specifically, I think you want this (untested):
> >
> > That should work but since -Wunreachable-code-fallthrough is off by
> > default, I did not really see a reason to include it in KBUILD_CFLAGS. I
> > do not have a strong opinion though, your version is smaller than mine
> > is so we can just go with that. I'll defer to Gustavo on it since he has
> > put in all of the work cleaning up the warnings.
>
>
>
> https://github.com/llvm/llvm-project/commit/9ed4a94d6451046a51ef393cd62f00710820a7e8
>
> did two things:
>
> (1) Change the -Wimplicit-fallthrough behavior so that it fits
> to our use in the kernel
>
> (2) Add a new option -Wunreachable-code-fallthrough
> that works like the previous -Wimplicit-fallthrough of
> Clang <= 13.0.0
>
>
> They are separate things.
>
> Checking the presence of -Wunreachable-code-fallthrough
> does not make sense since we are only interested in (1) here.
>
>
>
> So, checking the Clang version is sensible and matches
> the explanation in the comment block.
>
>
> Moreover, using $(shell test ...) is less expensive than cc-option.
>
>
> If you want to make it even faster, you can use only
> built-in functions, like this:
>
>
> # Warn about unmarked fall-throughs in switch statement.
> # Clang prior to 14.0.0 warned on unreachable fallthroughs with
> # -Wimplicit-fallthrough, which is unacceptable due to IS_ENABLED().
> # https://bugs.llvm.org/show_bug.cgi?id=51094
> ifeq ($(firstword $(sort $(CONFIG_CLANG_VERSION) 140000)),140000)
> KBUILD_CFLAGS += -Wimplicit-fallthrough
> endif
>
>
>
> The $(sort ...) is alphabetical sort, not numeric sort.
> It works for us because the minimum Clang version is 10.0.1
> (that is CONFIG_CLANG_VERSION is always 6-digit)
>
> It will break when Clang version 100.0.0 is released.
>
> But, before that, we will raise the minimum supported clang version,
> and this conditional will go away.

I'd much rather pay the cost of cc-option to have a more precise
check; Linus is right: when I upgrade AOSP's fork of LLVM, it may not
be the fully released version of clang-14 though we have already moved
the version numbers upstream to clang-14. I think we should strive to
prefer feature tests over version tests, which are brittle.

```
# Clang would warn about unreachable fall throughs until clang-14.
ifdef CONFIG_CC_IS_CLANG
ifneq ($(call cc-option,-Wunreachable-code-fallthrough),)
KBUILD_CFLAGS += -Wimplicit-fallthrough
endif
endif
```

Is precisely what we want.
--
Thanks,
~Nick Desaulniers