aboutsummaryrefslogtreecommitdiff
path: root/test/SemaObjC
diff options
context:
space:
mode:
authorAlex Lorenz <arphaman@gmail.com>2018-07-05 22:51:11 +0000
committerAlex Lorenz <arphaman@gmail.com>2018-07-05 22:51:11 +0000
commit7d013cb1a231fb165b41120e8aa786b044b0b8bd (patch)
treedb0197ab29102fe6adcbbd59f1970c97ba46db88 /test/SemaObjC
parent62c4c0fac382ca37cf8b1ace72f201d10f92cb18 (diff)
[Sema] -Wformat-pedantic only for NSInteger/NSUInteger %tu/%td on Darwin
The '%tu'/'%td' as formatting specifiers have been used to print out the NSInteger/NSUInteger values for a long time. Typically their ABI matches, but that's not the case on watchOS. The ABI difference boils down to the following: - Regular 32-bit darwin targets (like armv7) use 'ptrdiff_t' of type 'int', which matches 'NSInteger'. - WatchOS arm target (armv7k) uses 'ptrdiff_t' of type 'long', which doesn't match 'NSInteger' of type 'int'. Because of this ABI difference these specifiers trigger -Wformat warnings only for watchOS builds, which is really inconvenient for cross-platform code. This patch avoids this -Wformat warning for '%tu'/'%td' and NS[U]Integer only, and instead uses the new -Wformat-pedantic warning that JF introduced in https://reviews.llvm.org/D47290. This is acceptable because Darwin guarantees that, despite the watchOS ABI differences, sizeof(ptrdiff_t) == sizeof(NS[U]Integer), and alignof(ptrdiff_t) == alignof(NS[U]Integer) so the warning is therefore noisy for pedantic reasons. I'll update public documentation to ensure that this behaviour is properly communicated. rdar://41739204 Differential Revision: https://reviews.llvm.org/D48852 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@336396 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/SemaObjC')
-rw-r--r--test/SemaObjC/format-size-spec-nsinteger.m22
1 files changed, 22 insertions, 0 deletions
diff --git a/test/SemaObjC/format-size-spec-nsinteger.m b/test/SemaObjC/format-size-spec-nsinteger.m
index 9eb954ec51..e7c0a0dd10 100644
--- a/test/SemaObjC/format-size-spec-nsinteger.m
+++ b/test/SemaObjC/format-size-spec-nsinteger.m
@@ -1,5 +1,7 @@
// RUN: %clang_cc1 -triple thumbv7-apple-ios -Wno-objc-root-class -fsyntax-only -verify -Wformat %s
// RUN: %clang_cc1 -triple thumbv7-apple-ios -Wno-objc-root-class -fsyntax-only -verify -Wformat-pedantic -DPEDANTIC %s
+// RUN: %clang_cc1 -triple thumbv7k-apple-watchos2.0.0 -fsyntax-only -fblocks -verify %s
+// RUN: %clang_cc1 -triple thumbv7k-apple-watchos2.0.0 -fsyntax-only -fblocks -verify -Wformat-pedantic -DPEDANTIC %s
#if !defined(PEDANTIC)
// expected-no-diagnostics
@@ -8,9 +10,16 @@
#if __LP64__
typedef unsigned long NSUInteger;
typedef long NSInteger;
+typedef long ptrdiff_t;
#else
typedef unsigned int NSUInteger;
typedef int NSInteger;
+#if __is_target_os(watchos)
+ // Watch ABI uses long for ptrdiff_t.
+ typedef long ptrdiff_t;
+#else
+ typedef int ptrdiff_t;
+#endif
#endif
@class NSString;
@@ -28,3 +37,16 @@ void testSizeSpecifier() {
// expected-warning@-4 {{values of type 'NSUInteger' should not be used as format arguments; add an explicit cast to 'unsigned long' instead}}
#endif
}
+
+void testPtrdiffSpecifier(ptrdiff_t x) {
+ NSInteger i = 0;
+ NSUInteger j = 0;
+
+ NSLog(@"ptrdiff_t NSUinteger: %tu", j);
+ NSLog(@"ptrdiff_t NSInteger: %td", i);
+ NSLog(@"ptrdiff_t %tu, %td", x, x);
+#if __is_target_os(watchos) && defined(PEDANTIC)
+ // expected-warning@-4 {{values of type 'NSUInteger' should not be used as format arguments; add an explicit cast to 'unsigned long' instead}}
+ // expected-warning@-4 {{values of type 'NSInteger' should not be used as format arguments; add an explicit cast to 'long' instead}}
+#endif
+}