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

JF Bastien via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon May 7 14:03:58 PDT 2018


jfb added a comment.

In https://reviews.llvm.org/D42933#1090286, @smeenai wrote:

> Note that the alignment matters in addition to the size.


Sure, but AFAICT from `./lib/Basic/Targets/*` the alignment is also specified properly, is it not?

> The pattern I've seen internally is people using `%zd` for NSInteger and `%tu` for NSUInteger, since until clang 6 neither of those were format-checked at all.
> 
> I'd be fine with adding an option to relax the printf checking if the size and alignment of the specifier and the actual type match, even if the types themselves differ (`-Wformat-relaxed` or something similar), so that you'd still get warnings on cases where the specifier mismatch could cause runtime issues.

What are the cases that you're worried about? The only ones I'm trying to capture here are `NSInteger` with `%zd` and `NSUInteger` with `%zu`, are there others?

> I think that would be preferable to special-casing the Apple types.

If there are more that should be captured and a similar point solution doesn't apply, agreed. However I'd like to understand if we agree on the guarantees that the platform offers for the two specific cases I'm targeting.


Repository:
  rC Clang

https://reviews.llvm.org/D42933





More information about the cfe-commits mailing list