This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [pushed] microblaze-tdep: Add ATTRIBUTE_PRINTF to microblaze_debug


On 09/25/2017 03:14 PM, Michael Eager wrote:
> On 09/21/2017 05:11 AM, Simon Marchi wrote:
>> I am getting this warning with clang:
>>
>> /home/emaisin/src/binutils-gdb/gdb/microblaze-tdep.c:94:28: error:
>> format string is not a string literal [-Werror,-Wformat-nonliteral]
>>         vprintf_unfiltered (fmt, args);
>>                             ^~~
>>
>> Adding ATTRIBUTE_PRINTF to microblaze_debug gets rid of it. Strangely,
>> > gcc doesn't warn about non-literal format strings when calling vprintf
>> (or a vprintf-style function, like vprintf_unfiltered).  I filed this
>> gcc bug:
>>
>> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82206
> 
> I'll admit to not being familiar with the nuances of __attribute__
> ((format ...)),
> or why adding this to the function declaration of microblaze_debug()
> would suppress
> a diagnostic on the call to vprintf_unfiltered(), 

Because with that the compiler can assume that the 'fmt' argument
as passed down to microblaze_debug is a string literal.  I.e.,
the compiler can tell that the argument to vprintf_unfiltered is
itself transitively a string literal.

> but the better fix
> seems to me to
> be to turn off the obviously inappropriate -Wformat-nonliteral option in
> microblaze_debug() using
> #pragma GCC diagnostic ignored "-Wformat-nonliteral"

That doesn't make sense to me.

Thanks,
Pedro Alves


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]