JF Bastien | ec7d7f3 | 2018-06-22 21:54:40 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -triple thumbv7-apple-ios -Wno-objc-root-class -fsyntax-only -verify -Wformat %s |
| 2 | // RUN: %clang_cc1 -triple thumbv7-apple-ios -Wno-objc-root-class -fsyntax-only -verify -Wformat-pedantic -DPEDANTIC %s |
Alex Lorenz | b2043ac | 2018-07-05 22:51:11 +0000 | [diff] [blame] | 3 | // RUN: %clang_cc1 -triple thumbv7k-apple-watchos2.0.0 -fsyntax-only -fblocks -verify %s |
| 4 | // RUN: %clang_cc1 -triple thumbv7k-apple-watchos2.0.0 -fsyntax-only -fblocks -verify -Wformat-pedantic -DPEDANTIC %s |
JF Bastien | ec7d7f3 | 2018-06-22 21:54:40 +0000 | [diff] [blame] | 5 | |
| 6 | #if !defined(PEDANTIC) |
| 7 | // expected-no-diagnostics |
| 8 | #endif |
| 9 | |
| 10 | #if __LP64__ |
| 11 | typedef unsigned long NSUInteger; |
| 12 | typedef long NSInteger; |
Alex Lorenz | b2043ac | 2018-07-05 22:51:11 +0000 | [diff] [blame] | 13 | typedef long ptrdiff_t; |
JF Bastien | ec7d7f3 | 2018-06-22 21:54:40 +0000 | [diff] [blame] | 14 | #else |
| 15 | typedef unsigned int NSUInteger; |
| 16 | typedef int NSInteger; |
Alex Lorenz | b2043ac | 2018-07-05 22:51:11 +0000 | [diff] [blame] | 17 | #if __is_target_os(watchos) |
| 18 | // Watch ABI uses long for ptrdiff_t. |
| 19 | typedef long ptrdiff_t; |
| 20 | #else |
| 21 | typedef int ptrdiff_t; |
| 22 | #endif |
JF Bastien | ec7d7f3 | 2018-06-22 21:54:40 +0000 | [diff] [blame] | 23 | #endif |
| 24 | |
| 25 | @class NSString; |
| 26 | |
| 27 | extern void NSLog(NSString *format, ...); |
| 28 | |
| 29 | void testSizeSpecifier() { |
| 30 | NSInteger i = 0; |
| 31 | NSUInteger j = 0; |
| 32 | NSLog(@"max NSInteger = %zi", i); |
| 33 | NSLog(@"max NSUinteger = %zu", j); |
| 34 | |
| 35 | #if defined(PEDANTIC) |
| 36 | // expected-warning@-4 {{values of type 'NSInteger' should not be used as format arguments; add an explicit cast to 'long' instead}} |
| 37 | // expected-warning@-4 {{values of type 'NSUInteger' should not be used as format arguments; add an explicit cast to 'unsigned long' instead}} |
| 38 | #endif |
| 39 | } |
Alex Lorenz | b2043ac | 2018-07-05 22:51:11 +0000 | [diff] [blame] | 40 | |
| 41 | void testPtrdiffSpecifier(ptrdiff_t x) { |
| 42 | NSInteger i = 0; |
| 43 | NSUInteger j = 0; |
| 44 | |
| 45 | NSLog(@"ptrdiff_t NSUinteger: %tu", j); |
| 46 | NSLog(@"ptrdiff_t NSInteger: %td", i); |
| 47 | NSLog(@"ptrdiff_t %tu, %td", x, x); |
| 48 | #if __is_target_os(watchos) && defined(PEDANTIC) |
| 49 | // expected-warning@-4 {{values of type 'NSUInteger' should not be used as format arguments; add an explicit cast to 'unsigned long' instead}} |
| 50 | // expected-warning@-4 {{values of type 'NSInteger' should not be used as format arguments; add an explicit cast to 'long' instead}} |
| 51 | #endif |
| 52 | } |