blob: e7c0a0dd101117e0c8ce846b0048f6eb2e788e99 [file] [log] [blame]
JF Bastienec7d7f32018-06-22 21:54:40 +00001// 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 Lorenzb2043ac2018-07-05 22:51:11 +00003// 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 Bastienec7d7f32018-06-22 21:54:40 +00005
6#if !defined(PEDANTIC)
7// expected-no-diagnostics
8#endif
9
10#if __LP64__
11typedef unsigned long NSUInteger;
12typedef long NSInteger;
Alex Lorenzb2043ac2018-07-05 22:51:11 +000013typedef long ptrdiff_t;
JF Bastienec7d7f32018-06-22 21:54:40 +000014#else
15typedef unsigned int NSUInteger;
16typedef int NSInteger;
Alex Lorenzb2043ac2018-07-05 22:51:11 +000017#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 Bastienec7d7f32018-06-22 21:54:40 +000023#endif
24
25@class NSString;
26
27extern void NSLog(NSString *format, ...);
28
29void 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 Lorenzb2043ac2018-07-05 22:51:11 +000040
41void 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}