[PATCH] D42933: [Sema] Avoid -Wformat warning for NSInteger/NSUInteger 'int' values with %zu/%zi long specifiers

Shoaib Meenai via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed May 9 13:25:25 PDT 2018


smeenai added a comment.

Yeah, I think we all agree now that a portability warning isn't really tractable. Note that even for the warnings that motivated this diff, they should have only fired if `size_t` and NSInteger had separate types, so it wasn't a portability warning in that sense to begin with (as in, it would only warn if there was a mismatch for your current target, not if there was a potential mismatch for any target).

We still have two options:

1. Special-case NSInteger/NSUInteger on Apple platforms so that they can always be printed using `%z` without any issues.
2. Relax the format specifier warnings (either under a new warning option, e.g. `-Wformat-relaxed`, or by relaxing `-Wformat` itself and adding something like `-Wformat-pedantic`) so that you don't warn when the specifier and the actual type have the same size and alignment, even when the actual type is different (which would also cover the case in 1).

I'm personally in favor of 2, and I can start a discussion on cfe-dev if you think we should try to achieve a broader consensus. Whichever option we went with, we would also have to ensure that the optimizer didn't do anything bad (as @aaron.ballman pointed out), both now and in the future.


Repository:
  rC Clang

https://reviews.llvm.org/D42933





More information about the cfe-commits mailing list