[llvm] [clang] [Sema] Implement support for -Wformat-signedness (PR #74440)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Fri Dec 8 09:00:49 PST 2023
AaronBallman wrote:
> I have started to implement defining the -Wformat-signedness option config in clang/include/clang/Basic/DiagnosticSemaKinds.td as suggested originally by @hazohelet and I agree that the implementation is a lot cleaner that way. However before finishing implementing that I think we need to conclude what level of gcc compatibility that we aim for in clang.
>
> Below I list the characteristics of -Wformat-signedness that I have seen by testing it out in gcc and reading the gcc documentation (I have not inspected the gcc source code):
>
> 1. The option -Wformat-signedness is default off.
>
> 2. The -Wformat-signedness warnings are not enabled alone by the -Wformat option.
>
> 3. The -Wformat-signedness warnings are not enabled alone by the -Wformat-signedness option.
>
> 4. The -Wformat-signedness warnings are enabled by the option -Wformat together with the option -Wformat-signedness.
>
> 5. Parts of the -Wformat-signedness warnings (regarding scanf) are enabled by the options -Wformat together with the option -pedantic.
>
> 6. Warnings produced by -Wformat-signedness is reported as a -Wformat warnings (e.g "warning: format ‘%u’ expects argument of type ‘unsigned int’, but argument 2 has type ‘int’ [-Wformat=]"
>
> 7. Warnings produced by -Wformat-signedness can be suppressed by "#pragma GCC diagnostic ignored -Wformat"
>
>
> Which of the above points are important for us to follow in clang to get a reasonable gcc compatibility? To me I think point 1, 2 and maybe 7 is the most important to follow.
I agree, 1, 2, 4 (same idea as 2, basically), and 7 are the critical things we'd need for compatibility. I personally find 3, 5, and 6 to be kind of strange behavior though I can see how it would arise.
https://github.com/llvm/llvm-project/pull/74440
More information about the cfe-commits
mailing list