Building the Linux kernel with Clang and LLVM
 help / color / mirror / Atom feed
* [PATCH] x86/boot: Address clang -Wimplicit-fallthrough in vsprintf()
@ 2024-05-16 14:03 Nathan Chancellor
  2024-05-16 23:08 ` Justin Stitt
  2024-05-17  9:51 ` Borislav Petkov
  0 siblings, 2 replies; 7+ messages in thread
From: Nathan Chancellor @ 2024-05-16 14:03 UTC (permalink / raw
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86
  Cc: Bill Wendling, Justin Stitt, linux-kernel, llvm, patches,
	kernel test robot, Nathan Chancellor

After enabling -Wimplicit-fallthrough for the x86 boot code, clang
warns:

  arch/x86/boot/printf.c:257:3: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough]
    257 |                 case 'u':
        |                 ^

Clang is a little more pedantic than GCC, which does not warn when
falling through to a case that is just break or return. Clang's version
is more in line with the kernel's own stance in deprecated.rst, which
states that all switch/case blocks must end in either break,
fallthrough, continue, goto, or return. Add the missing break to silence
the warning.

Fixes: dd0716c2b877 ("x86/boot: Add a fallthrough annotation")
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202405162054.ryP73vy1-lkp@intel.com/
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---
 arch/x86/boot/printf.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/x86/boot/printf.c b/arch/x86/boot/printf.c
index c0ec1dc355ab..51dc14b714f6 100644
--- a/arch/x86/boot/printf.c
+++ b/arch/x86/boot/printf.c
@@ -254,6 +254,8 @@ int vsprintf(char *buf, const char *fmt, va_list args)
 		case 'd':
 		case 'i':
 			flags |= SIGN;
+			break;
+
 		case 'u':
 			break;
 

---
base-commit: dd0716c2b87792ebea30864e7ad1df461d4c1525
change-id: 20240516-x86-boot-fix-clang-implicit-fallthrough-fc5c9bb19765

Best regards,
-- 
Nathan Chancellor <nathan@kernel.org>


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] x86/boot: Address clang -Wimplicit-fallthrough in vsprintf()
  2024-05-16 14:03 [PATCH] x86/boot: Address clang -Wimplicit-fallthrough in vsprintf() Nathan Chancellor
@ 2024-05-16 23:08 ` Justin Stitt
  2024-05-17  9:51 ` Borislav Petkov
  1 sibling, 0 replies; 7+ messages in thread
From: Justin Stitt @ 2024-05-16 23:08 UTC (permalink / raw
  To: Nathan Chancellor
  Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	Bill Wendling, linux-kernel, llvm, patches, kernel test robot

On Thu, May 16, 2024 at 7:03 AM Nathan Chancellor <nathan@kernel.org> wrote:
>
> After enabling -Wimplicit-fallthrough for the x86 boot code, clang
> warns:
>
>   arch/x86/boot/printf.c:257:3: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough]
>     257 |                 case 'u':
>         |                 ^
>
> Clang is a little more pedantic than GCC, which does not warn when
> falling through to a case that is just break or return. Clang's version
> is more in line with the kernel's own stance in deprecated.rst, which
> states that all switch/case blocks must end in either break,
> fallthrough, continue, goto, or return. Add the missing break to silence
> the warning.
>
> Fixes: dd0716c2b877 ("x86/boot: Add a fallthrough annotation")
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202405162054.ryP73vy1-lkp@intel.com/
> Signed-off-by: Nathan Chancellor <nathan@kernel.org>

Seems simple enough.

Acked-by: Justin Stitt <justinstitt@google.com>

> ---
>  arch/x86/boot/printf.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/arch/x86/boot/printf.c b/arch/x86/boot/printf.c
> index c0ec1dc355ab..51dc14b714f6 100644
> --- a/arch/x86/boot/printf.c
> +++ b/arch/x86/boot/printf.c
> @@ -254,6 +254,8 @@ int vsprintf(char *buf, const char *fmt, va_list args)
>                 case 'd':
>                 case 'i':
>                         flags |= SIGN;
> +                       break;
> +
>                 case 'u':
>                         break;
>
>
> ---
> base-commit: dd0716c2b87792ebea30864e7ad1df461d4c1525
> change-id: 20240516-x86-boot-fix-clang-implicit-fallthrough-fc5c9bb19765
>
> Best regards,
> --
> Nathan Chancellor <nathan@kernel.org>
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] x86/boot: Address clang -Wimplicit-fallthrough in vsprintf()
  2024-05-16 14:03 [PATCH] x86/boot: Address clang -Wimplicit-fallthrough in vsprintf() Nathan Chancellor
  2024-05-16 23:08 ` Justin Stitt
@ 2024-05-17  9:51 ` Borislav Petkov
  2024-05-17 15:18   ` Nathan Chancellor
  1 sibling, 1 reply; 7+ messages in thread
From: Borislav Petkov @ 2024-05-17  9:51 UTC (permalink / raw
  To: Nathan Chancellor
  Cc: Thomas Gleixner, Ingo Molnar, Dave Hansen, x86, Bill Wendling,
	Justin Stitt, linux-kernel, llvm, patches, kernel test robot

On Thu, May 16, 2024 at 07:03:41AM -0700, Nathan Chancellor wrote:
> After enabling -Wimplicit-fallthrough for the x86 boot code, clang
> warns:
> 
>   arch/x86/boot/printf.c:257:3: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough]
>     257 |                 case 'u':
>         |                 ^
> 
> Clang is a little more pedantic than GCC, which does not warn when
> falling through to a case that is just break or return.

Is anyone fixing Clang?

:-P

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] x86/boot: Address clang -Wimplicit-fallthrough in vsprintf()
  2024-05-17  9:51 ` Borislav Petkov
@ 2024-05-17 15:18   ` Nathan Chancellor
  2024-05-23 11:57     ` Borislav Petkov
  0 siblings, 1 reply; 7+ messages in thread
From: Nathan Chancellor @ 2024-05-17 15:18 UTC (permalink / raw
  To: Borislav Petkov
  Cc: Thomas Gleixner, Ingo Molnar, Dave Hansen, x86, Bill Wendling,
	Justin Stitt, linux-kernel, llvm, patches, kernel test robot,
	Kees Cook

On Fri, May 17, 2024 at 11:51:10AM +0200, Borislav Petkov wrote:
> On Thu, May 16, 2024 at 07:03:41AM -0700, Nathan Chancellor wrote:
> > After enabling -Wimplicit-fallthrough for the x86 boot code, clang
> > warns:
> > 
> >   arch/x86/boot/printf.c:257:3: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough]
> >     257 |                 case 'u':
> >         |                 ^
> > 
> > Clang is a little more pedantic than GCC, which does not warn when
> > falling through to a case that is just break or return.
> 
> Is anyone fixing Clang?
> 
> :-P

There was a patch to make Clang match GCC's behavior a few years ago but
I think Kees made a good argument that GCC's behavior leaves potential
bugs on the table, so that was not pursued further.

https://reviews.llvm.org/D91895#2417170

It was brought up to GCC as well but they did not want to change their
behavior:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91432

Cheers,
Nathan

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] x86/boot: Address clang -Wimplicit-fallthrough in vsprintf()
  2024-05-17 15:18   ` Nathan Chancellor
@ 2024-05-23 11:57     ` Borislav Petkov
  2024-05-23 23:12       ` Kees Cook
  0 siblings, 1 reply; 7+ messages in thread
From: Borislav Petkov @ 2024-05-23 11:57 UTC (permalink / raw
  To: Nathan Chancellor
  Cc: Thomas Gleixner, Ingo Molnar, Dave Hansen, x86, Bill Wendling,
	Justin Stitt, linux-kernel, llvm, patches, kernel test robot,
	Kees Cook

On Fri, May 17, 2024 at 08:18:33AM -0700, Nathan Chancellor wrote:
> There was a patch to make Clang match GCC's behavior a few years ago but
> I think Kees made a good argument that GCC's behavior leaves potential
> bugs on the table, so that was not pursued further.
> 
> https://reviews.llvm.org/D91895#2417170

Really? Maybe I'm being dense but I don't see real bugs there... I see
readability issues. :-)

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] x86/boot: Address clang -Wimplicit-fallthrough in vsprintf()
  2024-05-23 11:57     ` Borislav Petkov
@ 2024-05-23 23:12       ` Kees Cook
  2024-05-24 16:39         ` Borislav Petkov
  0 siblings, 1 reply; 7+ messages in thread
From: Kees Cook @ 2024-05-23 23:12 UTC (permalink / raw
  To: Borislav Petkov
  Cc: Nathan Chancellor, Thomas Gleixner, Ingo Molnar, Dave Hansen, x86,
	Bill Wendling, Justin Stitt, linux-kernel, llvm, patches,
	kernel test robot

On Thu, May 23, 2024 at 01:57:34PM +0200, Borislav Petkov wrote:
> On Fri, May 17, 2024 at 08:18:33AM -0700, Nathan Chancellor wrote:
> > There was a patch to make Clang match GCC's behavior a few years ago but
> > I think Kees made a good argument that GCC's behavior leaves potential
> > bugs on the table, so that was not pursued further.
> > 
> > https://reviews.llvm.org/D91895#2417170
> 
> Really? Maybe I'm being dense but I don't see real bugs there... I see
> readability issues. :-)

There isn't a bug _here_, but this is about making the code unambiguous
everywhere in the kernel. We've already done the work to get rid of
all these warnings; this one is newly introduced, so let's get it fixed.

We don't want to have the same flow-control statement reachable from two
different "case"s where the resulting behaviors are different. Otherwise
we can't determine if a "fallthrough" is missing or intentional.

Reviewed-by: Kees Cook <keescook@chromium.org>

-Kees

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] x86/boot: Address clang -Wimplicit-fallthrough in vsprintf()
  2024-05-23 23:12       ` Kees Cook
@ 2024-05-24 16:39         ` Borislav Petkov
  0 siblings, 0 replies; 7+ messages in thread
From: Borislav Petkov @ 2024-05-24 16:39 UTC (permalink / raw
  To: Kees Cook
  Cc: Nathan Chancellor, Thomas Gleixner, Ingo Molnar, Dave Hansen, x86,
	Bill Wendling, Justin Stitt, linux-kernel, llvm, patches,
	kernel test robot

On Thu, May 23, 2024 at 04:12:25PM -0700, Kees Cook wrote:
> There isn't a bug _here_, but this is about making the code unambiguous
> everywhere in the kernel. We've already done the work to get rid of
> all these warnings; this one is newly introduced, so let's get it fixed.

Nah, it has been there since forever (forever == 2007 in this case). It
fires because I enabled the warning in the decompressor.

> We don't want to have the same flow-control statement reachable from two
> different "case"s where the resulting behaviors are different. Otherwise
> we can't determine if a "fallthrough" is missing or intentional.

I'd agree if this warning wasn't enabled by default but were a W=123...
diagnostic thing which does the additional checks. But right now clang
is warning for a perfectly valid, albeit a bit confusing C.

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-05-24 16:40 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-16 14:03 [PATCH] x86/boot: Address clang -Wimplicit-fallthrough in vsprintf() Nathan Chancellor
2024-05-16 23:08 ` Justin Stitt
2024-05-17  9:51 ` Borislav Petkov
2024-05-17 15:18   ` Nathan Chancellor
2024-05-23 11:57     ` Borislav Petkov
2024-05-23 23:12       ` Kees Cook
2024-05-24 16:39         ` Borislav Petkov

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 read-only IMAP folder(s) and NNTP newsgroup(s).