Skip to content

Commit b5960a0

Browse files
nathanchancepmladek
authored andcommitted
vsprintf: Use __diag macros to disable '-Wsuggest-attribute=format'
The GCC specific warning '-Wsuggest-attribute=format' is disabled around va_format() using raw #pragma statements, which includes an '#ifndef __clang__' to avoid a warning about an unknown warning option from clang (which recognizes '#pragma GCC' for compatibility reasons): lib/vsprintf.c:1703:32: error: unknown warning group '-Wsuggest-attribute=format', ignored [-Werror,-Wunknown-warning-option] 1703 | #pragma GCC diagnostic ignored "-Wsuggest-attribute=format" | ^ While the current solution works, it is not visually appealing. The kernel already has some infrastructure that wraps these #pragma statements to give more specific control over diagnostics without needing #ifdef blocks for different compilers. Convert the existing statements over to the __diag macros. Closes: https://lore.kernel.org/r/CAHk-=wgfX9nBGE0Ap9GjhOy7Mn=RSy=rx0MvqfYFFDx31KJXqQ@mail.gmail.com Signed-off-by: Nathan Chancellor <[email protected]> Tested-by: Andy Shevchenko <[email protected]> Reviewed-by: Petr Mladek <[email protected]> Link: https://patch.msgid.link/20250404-vsprintf-convert-pragmas-to-__diag-v1-2-5d6c5c55b2bd@kernel.org Signed-off-by: Petr Mladek <[email protected]>
1 parent 7efa84b commit b5960a0

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

lib/vsprintf.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1699,10 +1699,9 @@ char *escaped_string(char *buf, char *end, u8 *addr, struct printf_spec spec,
16991699
return buf;
17001700
}
17011701

1702-
#pragma GCC diagnostic push
1703-
#ifndef __clang__
1704-
#pragma GCC diagnostic ignored "-Wsuggest-attribute=format"
1705-
#endif
1702+
__diag_push();
1703+
__diag_ignore(GCC, all, "-Wsuggest-attribute=format",
1704+
"Not a valid __printf() conversion candidate.");
17061705
static char *va_format(char *buf, char *end, struct va_format *va_fmt,
17071706
struct printf_spec spec)
17081707
{
@@ -1717,7 +1716,7 @@ static char *va_format(char *buf, char *end, struct va_format *va_fmt,
17171716

17181717
return buf;
17191718
}
1720-
#pragma GCC diagnostic pop
1719+
__diag_pop();
17211720

17221721
static noinline_for_stack
17231722
char *uuid_string(char *buf, char *end, const u8 *addr,

0 commit comments

Comments
 (0)