Re: [PATCH] bug: shut up format attribute warning for clang as well

From: Nathan Chancellor

Date: Fri Mar 20 2026 - 20:08:38 EST


On Fri, Mar 20, 2026 at 10:14:25PM +0100, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@xxxxxxxx>
>
> 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@xxxxxxxx>

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@xxxxxxxxxx>

> ---
> 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
>