[clang] [llvm] [Sema] Implement support for -Wformat-signedness (PR #74440)

Aaron Ballman via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 6 11:50:28 PST 2023


AaronBallman wrote:

> > I'd like to understand the need for this diagnostic a bit more. I realize GCC has it, but it's off-by-default in GCC and `-Wformat` does not enable it either: https://godbolt.org/z/Gxczsjdj5
> > We believe that users don't enable off by default warnings often enough to warrant supporting them, and this feels like a very pedantic warning in many cases. e.g., `printf("%u", 0);`
> 
> I work on an out of tree backend and our customers requested the warning -Wformat-signedness to be implemented in clang (as they found it in gcc). I agree that the warning is pedantic. Note that gcc will with the options -Wformat and -pedantic enable at least the warnings related to scanf (see https://godbolt.org/z/WjzWKj89G).
> 
> If you feel that the clang community don't really want -Wformat-signedness I can simply implement this in our downstream llvm-project repo and abandon this pull request. We already have a large number of diffs compared to https://github.com/llvm/llvm-project and a few more probably don't make any difference.

Thank you for the details!

I think this is worth having. 1) GCC compatibility isn't unreasonable here, 2) there is evidence of users enabling this specific warning: https://sourcegraph.com/search?q=context:global+-Wformat-signedness+-file:.*gcc.*+-file:.*clang.*&patternType=standard&sm=1&groupBy=repo 3) The diagnostic is helpful for people who may need to debug situations where the printed or scanned values have an unexpected sign (e.g., expected a negative number, got a huge positive number or vice versa).

So despite it being a rather pedantic diagnostic, I think I'm convinced it meets the bar for us to include.

https://github.com/llvm/llvm-project/pull/74440


More information about the llvm-commits mailing list