2017-09-23 02:36:06 +08:00
|
|
|
// RUN: cp %s %t
|
[Sema] -Wformat-pedantic only for NSInteger/NSUInteger %zu/%zi on Darwin
Summary:
Pick D42933 back up, and make NSInteger/NSUInteger with %zu/%zi specifiers on Darwin warn only in pedantic mode. The default -Wformat recently started warning for the following code because of the added support for analysis for the '%zi' specifier.
NSInteger i = NSIntegerMax;
NSLog(@"max NSInteger = %zi", i);
The problem is that on armv7 %zi is 'long', and NSInteger is typedefed to 'int' in Foundation. We should avoid this warning as it's inconvenient to our users: it's target specific (happens only on armv7 and not arm64), and breaks their existing code. We should also silence the warning for the '%zu' specifier to ensure consistency. This is acceptable because Darwin guarantees that, despite the unfortunate choice of typedef, sizeof(size_t) == sizeof(NS[U]Integer), the warning is therefore noisy for pedantic reasons. Once this is in I'll update public documentation.
Related discussion on cfe-dev:
http://lists.llvm.org/pipermail/cfe-dev/2018-May/058050.html
<rdar://36874921&40501559>
Reviewers: ahatanak, vsapsai, alexshap, aaron.ballman, javed.absar, jfb, rjmccall
Subscribers: kristof.beyls, aheejin, cfe-commits
Differential Revision: https://reviews.llvm.org/D47290
llvm-svn: 335393
2018-06-23 05:54:40 +08:00
|
|
|
// RUN: %clang_cc1 -triple thumbv7-apple-ios8.0.0 -fsyntax-only -Wformat-pedantic -fixit %t
|
2017-09-23 02:36:06 +08:00
|
|
|
// RUN: grep -v CHECK %t | FileCheck %s
|
|
|
|
|
|
|
|
int printf(const char * restrict, ...);
|
|
|
|
typedef unsigned int NSUInteger;
|
|
|
|
typedef int NSInteger;
|
|
|
|
NSUInteger getNSUInteger();
|
|
|
|
NSInteger getNSInteger();
|
|
|
|
|
|
|
|
void test() {
|
|
|
|
// For thumbv7-apple-ios8.0.0 the underlying type of ssize_t is long
|
|
|
|
// and the underlying type of size_t is unsigned long.
|
|
|
|
|
|
|
|
printf("test 1: %zu", getNSUInteger());
|
|
|
|
// CHECK: printf("test 1: %lu", (unsigned long)getNSUInteger());
|
|
|
|
|
|
|
|
printf("test 2: %zu %zu", getNSUInteger(), getNSUInteger());
|
|
|
|
// CHECK: printf("test 2: %lu %lu", (unsigned long)getNSUInteger(), (unsigned long)getNSUInteger());
|
|
|
|
|
|
|
|
printf("test 3: %zd", getNSInteger());
|
|
|
|
// CHECK: printf("test 3: %ld", (long)getNSInteger());
|
|
|
|
|
|
|
|
printf("test 4: %zd %zd", getNSInteger(), getNSInteger());
|
|
|
|
// CHECK: printf("test 4: %ld %ld", (long)getNSInteger(), (long)getNSInteger());
|
|
|
|
}
|