<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/60718>60718</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Clang flag -Wmissing-format-attribute doesn't catch missing attributes
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
jstengleingithub
</td>
</tr>
</table>
<pre>
gcc has a valuable flag -Wmissing-format-attribute which shows functions missing a format attribute. While clang supports this flag, it currently doesn't do anything.
Code:
```c
#include <stddef.h>
#include <string.h>
#include <stdarg.h>
#include <stdio.h>
void safe_snprintf(char *outstring, const size_t length, const char *format, ... /* args */);
void safe_snprintf(char *outstring, const size_t length, const char *format, ... /* args */)
{
va_list args;
va_start(args, format);
if ((outstring != NULL) && (length > 0)) {
vsnprintf(outstring, length, format, args);
outstring[length - 1] = 0;
}
va_end(args);
}
```
gcc warning:
```sh
gcc -c -Wmissing-format-attribute test.c
test.c: In function 'safe_snprintf':
test.c:18:9: warning: function 'safe_snprintf' might be a candidate for 'gnu_printf' format attribute [-Wsuggest-attribute=format]
vsnprintf(outstring, length, format, args);
^~~~~~~~~
gcc --version
gcc (GCC) 8.4.1 20200928 (Red Hat 8.4.1-1)
```
Clang supports the flag but finds no issue:
```sh
./clang -Wmissing-format-attribute -c ../../test.c
(no warning)
./clang --version
Clang version 17.0.0 6ac13a798adae9a40023200dcaa6ed2e9fd9033a)
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzEVTuP4zYQ_jV0M5BADa1XocJrn5MAhxQBgisXI5KSeJCphUh5sSny2wNaWsne5DZFihCGDM7zm-E8yDnTWq0rlj6x9LSjyXfDWH13Xtu218a2xndTvasH9Va1UkJHDgiu1E9U9xqanlqIvl2Mc8a2UTOMF_IReT-aevIaXjsjO3Dd8Oqgmaz0ZrAOFnEgmBVgVYjhW2d6DbIn24KbXl6G0Tvw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