In FreeBSD, we have been carrying around a custom patch for clang, since about four and a half years, to enable checking the FreeBSD kernel specific printf format specifiers: %b, %D, %r and %y. This patch was based on an earlier custom patch for gcc, with similar functionality, and it added a new -fformat-extensions option to enable those non-standard specifiers.
A few years ago we tried getting this patch upstreamed to llvm/clang, but it was not met with great enthusiasm. I think this was mostly because adding an option was seen as ugly, and even then, the option name did not convey that it was specifically meant for FreeBSD only.
I have now tried to massage the patch so that it is hopefully more palatable:
- It adds a new freebsd_kprintf format string type, which enables checking when used in attribute((format(...))) attributes
- Checks %b, %D, %r and %y specifiers, using existing diagnostic messages
- Adds test cases for all these specifiers
Now, I know the printf format checking might be due for a big overhaul, and this patch is not the prettiest around, but please consider that it implements functionality that we really need, and use. So I would rather get this in, and have it be part of some later restructuring, instead of having to forward-port it each new release... :)