Re: lib/vsprintf.c:1528:9: warning: function 'va_format' might be a candidate for 'gnu_printf' format attribute

From: Rasmus Villemoes
Date: Tue Feb 13 2024 - 07:06:07 EST


On 21/01/2024 14.54, Andy Shevchenko wrote:
> On Thu, Jan 11, 2024 at 10:33:09AM +0800, kernel test robot wrote:
>> tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
>> head: acc657692aed438e9931438f8c923b2b107aebf9
>> commit: 45c3e93d751ea50861c796da3cbfc848fa6ddf55 vsprintf: Factor out %pV handler as va_format()
>> date: 4 years, 9 months ago
>
> Blast from the past?!
>
> ..
>
>> lib/vsprintf.c: In function 'va_format':
>>>> lib/vsprintf.c:1528:9: warning: function 'va_format' might be a candidate for 'gnu_printf' format attribute [-Wsuggest-attribute=format]
>> 1528 | buf += vsnprintf(buf, end > buf ? end - buf : 0, va_fmt->fmt, va);
>> | ^~~
>
> This might be still valid, but I have no idea how to properly fix it.
>

It's a bogus warning, and the fix belongs in the compiler. When
vsnprintf() is called, but neither the format arg nor the va_list arg
are direct arguments to the caller (and the va_list is not built from
actual varargs using va_start()), there's absolutely no way a __printf
attribute could be appropriate.

IDK if we can shut up the test robot by locally disabling the
Wsuggest-attribute with some pragma.

Rasmus