public inbox for llvm@lists.linux.dev
 help / color / mirror / Atom feed
* [PATCH] bug: shut up format attribute warning for clang as well
@ 2026-03-20 21:14 Arnd Bergmann
  2026-03-21  0:08 ` Nathan Chancellor
  2026-03-23 10:54 ` Brendan Jackman
  0 siblings, 2 replies; 7+ messages in thread
From: Arnd Bergmann @ 2026-03-20 21:14 UTC (permalink / raw)
  To: Andrew Morton, Nathan Chancellor, Peter Zijlstra (Intel),
	Ingo Molnar, Brendan Jackman
  Cc: Arnd Bergmann, Nick Desaulniers, Bill Wendling, Justin Stitt,
	linux-kernel, llvm

From: Arnd Bergmann <arnd@arndb.de>

Like gcc, clang-22 now also warns about a function that it
incorrectly identifies as a printf-style format:

lib/bug.c:190:22: error: diagnostic behavior may be improved by adding the 'format(printf, 1, 0)' attribute to the declaration of '__warn_printf' [-Werror,-Wmissing-format-attribute]
  179 | static void __warn_printf(const char *fmt, struct pt_regs *regs)
      | __attribute__((format(printf, 1, 0)))
  180 | {
  181 |         if (!fmt)
  182 |                 return;
  183 |
  184 | #ifdef HAVE_ARCH_BUG_FORMAT_ARGS
  185 |         if (regs) {
  186 |                 struct arch_va_list _args;
  187 |                 va_list *args = __warn_args(&_args, regs);
  188 |
  189 |                 if (args) {
  190 |                         vprintk(fmt, *args);
      |                                           ^

Turn off this warning for all compilers and versions.

Fixes: d36067d6ea00 ("bug: Hush suggest-attribute=format for __warn_printf()")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 lib/bug.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/lib/bug.c b/lib/bug.c
index bbc301097749..374feb144f0b 100644
--- a/lib/bug.c
+++ b/lib/bug.c
@@ -174,8 +174,7 @@ struct bug_entry *find_bug(unsigned long bugaddr)
 }
 
 __diag_push();
-__diag_ignore(GCC, all, "-Wsuggest-attribute=format",
-	      "Not a valid __printf() conversion candidate.");
+__diag_ignore_all("-Wmissing-format-attribute", "Not a valid __printf() conversion candidate.");
 static void __warn_printf(const char *fmt, struct pt_regs *regs)
 {
 	if (!fmt)
-- 
2.39.5


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

* Re: [PATCH] bug: shut up format attribute warning for clang as well
  2026-03-20 21:14 [PATCH] bug: shut up format attribute warning for clang as well Arnd Bergmann
@ 2026-03-21  0:08 ` Nathan Chancellor
  2026-03-23 10:54 ` Brendan Jackman
  1 sibling, 0 replies; 7+ messages in thread
From: Nathan Chancellor @ 2026-03-21  0:08 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Andrew Morton, Peter Zijlstra (Intel), Ingo Molnar,
	Brendan Jackman, Arnd Bergmann, Nick Desaulniers, Bill Wendling,
	Justin Stitt, linux-kernel, llvm

On Fri, Mar 20, 2026 at 10:14:25PM +0100, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
> 
> Like gcc, clang-22 now also warns about a function that it
> incorrectly identifies as a printf-style format:
> 
> lib/bug.c:190:22: error: diagnostic behavior may be improved by adding the 'format(printf, 1, 0)' attribute to the declaration of '__warn_printf' [-Werror,-Wmissing-format-attribute]
>   179 | static void __warn_printf(const char *fmt, struct pt_regs *regs)
>       | __attribute__((format(printf, 1, 0)))
>   180 | {
>   181 |         if (!fmt)
>   182 |                 return;
>   183 |
>   184 | #ifdef HAVE_ARCH_BUG_FORMAT_ARGS
>   185 |         if (regs) {
>   186 |                 struct arch_va_list _args;
>   187 |                 va_list *args = __warn_args(&_args, regs);
>   188 |
>   189 |                 if (args) {
>   190 |                         vprintk(fmt, *args);
>       |                                           ^
> 
> Turn off this warning for all compilers and versions.
> 
> Fixes: d36067d6ea00 ("bug: Hush suggest-attribute=format for __warn_printf()")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Yeah, it looks like this flag has been recognized by clang for a long
time for GCC compatibility but it only recently started matching GCC's
behavior.

Reviewed-by: Nathan Chancellor <nathan@kernel.org>

> ---
>  lib/bug.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/lib/bug.c b/lib/bug.c
> index bbc301097749..374feb144f0b 100644
> --- a/lib/bug.c
> +++ b/lib/bug.c
> @@ -174,8 +174,7 @@ struct bug_entry *find_bug(unsigned long bugaddr)
>  }
>  
>  __diag_push();
> -__diag_ignore(GCC, all, "-Wsuggest-attribute=format",
> -	      "Not a valid __printf() conversion candidate.");
> +__diag_ignore_all("-Wmissing-format-attribute", "Not a valid __printf() conversion candidate.");
>  static void __warn_printf(const char *fmt, struct pt_regs *regs)
>  {
>  	if (!fmt)
> -- 
> 2.39.5
> 

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

* Re: [PATCH] bug: shut up format attribute warning for clang as well
  2026-03-20 21:14 [PATCH] bug: shut up format attribute warning for clang as well Arnd Bergmann
  2026-03-21  0:08 ` Nathan Chancellor
@ 2026-03-23 10:54 ` Brendan Jackman
  2026-03-23 15:38   ` Arnd Bergmann
  1 sibling, 1 reply; 7+ messages in thread
From: Brendan Jackman @ 2026-03-23 10:54 UTC (permalink / raw)
  To: Arnd Bergmann, Andrew Morton, Nathan Chancellor,
	Peter Zijlstra (Intel), Ingo Molnar, Brendan Jackman
  Cc: Arnd Bergmann, Nick Desaulniers, Bill Wendling, Justin Stitt,
	linux-kernel, llvm

On Fri Mar 20, 2026 at 9:14 PM UTC, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
>
> Like gcc, clang-22 now also warns about a function that it
> incorrectly identifies as a printf-style format:
>
> lib/bug.c:190:22: error: diagnostic behavior may be improved by adding the 'format(printf, 1, 0)' attribute to the declaration of '__warn_printf' [-Werror,-Wmissing-format-attribute]
>   179 | static void __warn_printf(const char *fmt, struct pt_regs *regs)
>       | __attribute__((format(printf, 1, 0)))
>   180 | {
>   181 |         if (!fmt)
>   182 |                 return;
>   183 |
>   184 | #ifdef HAVE_ARCH_BUG_FORMAT_ARGS
>   185 |         if (regs) {
>   186 |                 struct arch_va_list _args;
>   187 |                 va_list *args = __warn_args(&_args, regs);
>   188 |
>   189 |                 if (args) {
>   190 |                         vprintk(fmt, *args);
>       |                                           ^
>
> Turn off this warning for all compilers and versions.
>
> Fixes: d36067d6ea00 ("bug: Hush suggest-attribute=format for __warn_printf()")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  lib/bug.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/lib/bug.c b/lib/bug.c
> index bbc301097749..374feb144f0b 100644
> --- a/lib/bug.c
> +++ b/lib/bug.c
> @@ -174,8 +174,7 @@ struct bug_entry *find_bug(unsigned long bugaddr)
>  }
>  
>  __diag_push();
> -__diag_ignore(GCC, all, "-Wsuggest-attribute=format",
> -	      "Not a valid __printf() conversion candidate.");
> +__diag_ignore_all("-Wmissing-format-attribute", "Not a valid __printf() conversion candidate.");
>  static void __warn_printf(const char *fmt, struct pt_regs *regs)
>  {
>  	if (!fmt)

There is actually a superior fix for this warning that Andy Schevchenko
posted here (mine just happened to get merged first):

https://lore.kernel.org/all/20251208141618.2805983-1-andriy.shevchenko@linux.intel.com/T/#u

Should we just switch over to that? Looks like it should work for both
compilers.

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

* Re: [PATCH] bug: shut up format attribute warning for clang as well
  2026-03-23 10:54 ` Brendan Jackman
@ 2026-03-23 15:38   ` Arnd Bergmann
  2026-03-23 20:45     ` Andrew Morton
  0 siblings, 1 reply; 7+ messages in thread
From: Arnd Bergmann @ 2026-03-23 15:38 UTC (permalink / raw)
  To: Brendan Jackman, Arnd Bergmann, Andrew Morton, Nathan Chancellor,
	Peter Zijlstra, Ingo Molnar
  Cc: Nick Desaulniers, Bill Wendling, Justin Stitt, linux-kernel, llvm,
	andriy.shevchenko

On Mon, Mar 23, 2026, at 11:54, Brendan Jackman wrote:
> On Fri Mar 20, 2026 at 9:14 PM UTC, Arnd Bergmann wrote:
>
> There is actually a superior fix for this warning that Andy Schevchenko
> posted here (mine just happened to get merged first):
>
> https://lore.kernel.org/all/20251208141618.2805983-1-andriy.shevchenko@linux.intel.com/T/#u
>
> Should we just switch over to that? Looks like it should work for both
> compilers.

Right, I tried that again and it works. I had confused it with the
similar logic to disable the warning on va_format(), which is
not that easy to avoid.

    Arnd

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

* Re: [PATCH] bug: shut up format attribute warning for clang as well
  2026-03-23 15:38   ` Arnd Bergmann
@ 2026-03-23 20:45     ` Andrew Morton
  2026-03-23 20:56       ` Arnd Bergmann
  0 siblings, 1 reply; 7+ messages in thread
From: Andrew Morton @ 2026-03-23 20:45 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Brendan Jackman, Arnd Bergmann, Nathan Chancellor, Peter Zijlstra,
	Ingo Molnar, Nick Desaulniers, Bill Wendling, Justin Stitt,
	linux-kernel, llvm, andriy.shevchenko

On Mon, 23 Mar 2026 16:38:14 +0100 "Arnd Bergmann" <arnd@arndb.de> wrote:

> On Mon, Mar 23, 2026, at 11:54, Brendan Jackman wrote:
> > On Fri Mar 20, 2026 at 9:14 PM UTC, Arnd Bergmann wrote:
> >
> > There is actually a superior fix for this warning that Andy Schevchenko
> > posted here (mine just happened to get merged first):
> >
> > https://lore.kernel.org/all/20251208141618.2805983-1-andriy.shevchenko@linux.intel.com/T/#u
> >
> > Should we just switch over to that? Looks like it should work for both
> > compilers.
> 
> Right, I tried that again and it works. I had confused it with the
> similar logic to disable the warning on va_format(), which is
> not that easy to avoid.
> 

What I think I'm hearing is that we should revert Brendan's
d36067d6ea00 ("bug: Hush suggest-attribute=format for __warn_printf()")
then apply Andy's
https://lore.kernel.org/all/20251208141618.2805983-1-andriy.shevchenko@linux.intel.com/T/#u,
yes?

Could someone please prepare a suitably changelogged and tested patch
for that?

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

* Re: [PATCH] bug: shut up format attribute warning for clang as well
  2026-03-23 20:45     ` Andrew Morton
@ 2026-03-23 20:56       ` Arnd Bergmann
  2026-03-24 11:26         ` Andy Shevchenko
  0 siblings, 1 reply; 7+ messages in thread
From: Arnd Bergmann @ 2026-03-23 20:56 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Brendan Jackman, Arnd Bergmann, Nathan Chancellor, Peter Zijlstra,
	Ingo Molnar, Nick Desaulniers, Bill Wendling, Justin Stitt,
	linux-kernel, llvm, Andy Shevchenko

On Mon, Mar 23, 2026, at 21:45, Andrew Morton wrote:
> On Mon, 23 Mar 2026 16:38:14 +0100 "Arnd Bergmann" <arnd@arndb.de> wrote:
>
>> On Mon, Mar 23, 2026, at 11:54, Brendan Jackman wrote:
>> > On Fri Mar 20, 2026 at 9:14 PM UTC, Arnd Bergmann wrote:
>> >
>> > There is actually a superior fix for this warning that Andy Schevchenko
>> > posted here (mine just happened to get merged first):
>> >
>> > https://lore.kernel.org/all/20251208141618.2805983-1-andriy.shevchenko@linux.intel.com/T/#u
>> >
>> > Should we just switch over to that? Looks like it should work for both
>> > compilers.
>> 
>> Right, I tried that again and it works. I had confused it with the
>> similar logic to disable the warning on va_format(), which is
>> not that easy to avoid.
>> 
>
> What I think I'm hearing is that we should revert Brendan's
> d36067d6ea00 ("bug: Hush suggest-attribute=format for __warn_printf()")
> then apply Andy's
> https://lore.kernel.org/all/20251208141618.2805983-1-andriy.shevchenko@linux.intel.com/T/#u,
> yes?
>
> Could someone please prepare a suitably changelogged and tested patch
> for that?

I now sent the version that I had in my tree already as a v2
of my patch. I tested this with gcc-16 and clang-22 in random
configurations.

     Arnd

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

* Re: [PATCH] bug: shut up format attribute warning for clang as well
  2026-03-23 20:56       ` Arnd Bergmann
@ 2026-03-24 11:26         ` Andy Shevchenko
  0 siblings, 0 replies; 7+ messages in thread
From: Andy Shevchenko @ 2026-03-24 11:26 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Andrew Morton, Brendan Jackman, Arnd Bergmann, Nathan Chancellor,
	Peter Zijlstra, Ingo Molnar, Nick Desaulniers, Bill Wendling,
	Justin Stitt, linux-kernel, llvm

On Mon, Mar 23, 2026 at 09:56:31PM +0100, Arnd Bergmann wrote:
> On Mon, Mar 23, 2026, at 21:45, Andrew Morton wrote:
> > On Mon, 23 Mar 2026 16:38:14 +0100 "Arnd Bergmann" <arnd@arndb.de> wrote:
> >> On Mon, Mar 23, 2026, at 11:54, Brendan Jackman wrote:
> >> > On Fri Mar 20, 2026 at 9:14 PM UTC, Arnd Bergmann wrote:
> >> >
> >> > There is actually a superior fix for this warning that Andy Schevchenko
> >> > posted here (mine just happened to get merged first):
> >> >
> >> > https://lore.kernel.org/all/20251208141618.2805983-1-andriy.shevchenko@linux.intel.com/T/#u
> >> >
> >> > Should we just switch over to that? Looks like it should work for both
> >> > compilers.
> >> 
> >> Right, I tried that again and it works. I had confused it with the
> >> similar logic to disable the warning on va_format(), which is
> >> not that easy to avoid.
> >
> > What I think I'm hearing is that we should revert Brendan's
> > d36067d6ea00 ("bug: Hush suggest-attribute=format for __warn_printf()")
> > then apply Andy's
> > https://lore.kernel.org/all/20251208141618.2805983-1-andriy.shevchenko@linux.intel.com/T/#u,
> > yes?
> >
> > Could someone please prepare a suitably changelogged and tested patch
> > for that?
> 
> I now sent the version that I had in my tree already as a v2
> of my patch. I tested this with gcc-16 and clang-22 in random
> configurations.

Thank you!

-- 
With Best Regards,
Andy Shevchenko



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

end of thread, other threads:[~2026-03-24 11:26 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-20 21:14 [PATCH] bug: shut up format attribute warning for clang as well Arnd Bergmann
2026-03-21  0:08 ` Nathan Chancellor
2026-03-23 10:54 ` Brendan Jackman
2026-03-23 15:38   ` Arnd Bergmann
2026-03-23 20:45     ` Andrew Morton
2026-03-23 20:56       ` Arnd Bergmann
2026-03-24 11:26         ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox