annotate clang/test/FixIt/format.m @ 165:597b3f1c2c93

fix call createTailCallEliminationPass
author anatofuz
date Tue, 24 Mar 2020 15:30:52 +0900
parents 1d019706d866
children 2e18cbf3894f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // RUN: %clang_cc1 -triple %itanium_abi_triple -fsyntax-only -fblocks -verify %s
anatofuz
parents:
diff changeset
2 // RUN: %clang_cc1 -triple %itanium_abi_triple -fdiagnostics-parseable-fixits -fblocks %s 2>&1 | FileCheck %s
anatofuz
parents:
diff changeset
3
anatofuz
parents:
diff changeset
4 @class NSString;
anatofuz
parents:
diff changeset
5 extern void NSLog(NSString *, ...);
anatofuz
parents:
diff changeset
6 int printf(const char * restrict, ...) ;
anatofuz
parents:
diff changeset
7
anatofuz
parents:
diff changeset
8 void test_integer_correction (int x) {
anatofuz
parents:
diff changeset
9 printf("%d", x); // no-warning
anatofuz
parents:
diff changeset
10 printf("%s", x); // expected-warning{{format specifies type 'char *' but the argument has type 'int'}}
anatofuz
parents:
diff changeset
11 printf("%lf", x); // expected-warning{{format specifies type 'double' but the argument has type 'int'}}
anatofuz
parents:
diff changeset
12 // CHECK: fix-it:"{{.*}}":{10:11-10:13}:"%d"
anatofuz
parents:
diff changeset
13 // CHECK: fix-it:"{{.*}}":{11:11-11:14}:"%d"
anatofuz
parents:
diff changeset
14
anatofuz
parents:
diff changeset
15 NSLog(@"%d", x); // no-warning
anatofuz
parents:
diff changeset
16 NSLog(@"%s", x); // expected-warning{{format specifies type 'char *' but the argument has type 'int'}}
anatofuz
parents:
diff changeset
17 NSLog(@"%lf", x); // expected-warning{{format specifies type 'double' but the argument has type 'int'}}
anatofuz
parents:
diff changeset
18 NSLog(@"%@", x); // expected-warning{{format specifies type 'id' but the argument has type 'int'}}
anatofuz
parents:
diff changeset
19 // CHECK: fix-it:"{{.*}}":{16:11-16:13}:"%d"
anatofuz
parents:
diff changeset
20 // CHECK: fix-it:"{{.*}}":{17:11-17:14}:"%d"
anatofuz
parents:
diff changeset
21 // CHECK: fix-it:"{{.*}}":{18:11-18:13}:"%d"
anatofuz
parents:
diff changeset
22 }
anatofuz
parents:
diff changeset
23
anatofuz
parents:
diff changeset
24 void test_string_correction (char *x) {
anatofuz
parents:
diff changeset
25 printf("%d", x); // expected-warning{{format specifies type 'int' but the argument has type 'char *'}}
anatofuz
parents:
diff changeset
26 printf("%s", x); // no-warning
anatofuz
parents:
diff changeset
27 printf("%lf", x); // expected-warning{{format specifies type 'double' but the argument has type 'char *'}}
anatofuz
parents:
diff changeset
28 // CHECK: fix-it:"{{.*}}":{25:11-25:13}:"%s"
anatofuz
parents:
diff changeset
29 // CHECK: fix-it:"{{.*}}":{27:11-27:14}:"%s"
anatofuz
parents:
diff changeset
30
anatofuz
parents:
diff changeset
31 NSLog(@"%d", x); // expected-warning{{format specifies type 'int' but the argument has type 'char *'}}
anatofuz
parents:
diff changeset
32 NSLog(@"%s", x); // no-warning
anatofuz
parents:
diff changeset
33 NSLog(@"%lf", x); // expected-warning{{format specifies type 'double' but the argument has type 'char *'}}
anatofuz
parents:
diff changeset
34 NSLog(@"%@", x); // expected-warning{{format specifies type 'id' but the argument has type 'char *'}}
anatofuz
parents:
diff changeset
35 // CHECK: fix-it:"{{.*}}":{31:11-31:13}:"%s"
anatofuz
parents:
diff changeset
36 // CHECK: fix-it:"{{.*}}":{33:11-33:14}:"%s"
anatofuz
parents:
diff changeset
37 // CHECK: fix-it:"{{.*}}":{34:11-34:13}:"%s"
anatofuz
parents:
diff changeset
38 }
anatofuz
parents:
diff changeset
39
anatofuz
parents:
diff changeset
40 void test_object_correction (id x) {
anatofuz
parents:
diff changeset
41 NSLog(@"%d", x); // expected-warning{{format specifies type 'int' but the argument has type 'id'}}
anatofuz
parents:
diff changeset
42 NSLog(@"%s", x); // expected-warning{{format specifies type 'char *' but the argument has type 'id'}}
anatofuz
parents:
diff changeset
43 NSLog(@"%lf", x); // expected-warning{{format specifies type 'double' but the argument has type 'id'}}
anatofuz
parents:
diff changeset
44 NSLog(@"%@", x); // no-warning
anatofuz
parents:
diff changeset
45 // CHECK: fix-it:"{{.*}}":{41:11-41:13}:"%@"
anatofuz
parents:
diff changeset
46 // CHECK: fix-it:"{{.*}}":{42:11-42:13}:"%@"
anatofuz
parents:
diff changeset
47 // CHECK: fix-it:"{{.*}}":{43:11-43:14}:"%@"
anatofuz
parents:
diff changeset
48 }
anatofuz
parents:
diff changeset
49
anatofuz
parents:
diff changeset
50 typedef const struct __CFString * __attribute__((NSObject)) CFStringRef;
anatofuz
parents:
diff changeset
51 void test_cf_object_correction (CFStringRef x) {
anatofuz
parents:
diff changeset
52 NSLog(@"%d", x); // expected-warning{{format specifies type 'int' but the argument has type 'CFStringRef'}}
anatofuz
parents:
diff changeset
53 NSLog(@"%s", x); // expected-warning{{format specifies type 'char *' but the argument has type 'CFStringRef'}}
anatofuz
parents:
diff changeset
54 NSLog(@"%lf", x); // expected-warning{{format specifies type 'double' but the argument has type 'CFStringRef'}}
anatofuz
parents:
diff changeset
55 NSLog(@"%@", x); // no-warning
anatofuz
parents:
diff changeset
56 // CHECK: fix-it:"{{.*}}":{52:11-52:13}:"%@"
anatofuz
parents:
diff changeset
57 // CHECK: fix-it:"{{.*}}":{53:11-53:13}:"%@"
anatofuz
parents:
diff changeset
58 // CHECK: fix-it:"{{.*}}":{54:11-54:14}:"%@"
anatofuz
parents:
diff changeset
59 }
anatofuz
parents:
diff changeset
60
anatofuz
parents:
diff changeset
61 typedef void (^block_t)(void);
anatofuz
parents:
diff changeset
62 void test_block_correction (block_t x) {
anatofuz
parents:
diff changeset
63 NSLog(@"%d", x); // expected-warning{{format specifies type 'int' but the argument has type 'block_t'}}
anatofuz
parents:
diff changeset
64 NSLog(@"%s", x); // expected-warning{{format specifies type 'char *' but the argument has type 'block_t'}}
anatofuz
parents:
diff changeset
65 NSLog(@"%lf", x); // expected-warning{{format specifies type 'double' but the argument has type 'block_t'}}
anatofuz
parents:
diff changeset
66 NSLog(@"%@", x); // no-warning
anatofuz
parents:
diff changeset
67 // CHECK: fix-it:"{{.*}}":{63:11-63:13}:"%@"
anatofuz
parents:
diff changeset
68 // CHECK: fix-it:"{{.*}}":{64:11-64:13}:"%@"
anatofuz
parents:
diff changeset
69 // CHECK: fix-it:"{{.*}}":{65:11-65:14}:"%@"
anatofuz
parents:
diff changeset
70 }
anatofuz
parents:
diff changeset
71
anatofuz
parents:
diff changeset
72 void test_class_correction (Class x) {
anatofuz
parents:
diff changeset
73 NSLog(@"%d", x); // expected-warning{{format specifies type 'int' but the argument has type 'Class'}}
anatofuz
parents:
diff changeset
74 NSLog(@"%s", x); // expected-warning{{format specifies type 'char *' but the argument has type 'Class'}}
anatofuz
parents:
diff changeset
75 NSLog(@"%lf", x); // expected-warning{{format specifies type 'double' but the argument has type 'Class'}}
anatofuz
parents:
diff changeset
76 NSLog(@"%@", x); // no-warning
anatofuz
parents:
diff changeset
77 // CHECK: fix-it:"{{.*}}":{73:11-73:13}:"%@"
anatofuz
parents:
diff changeset
78 // CHECK: fix-it:"{{.*}}":{74:11-74:13}:"%@"
anatofuz
parents:
diff changeset
79 // CHECK: fix-it:"{{.*}}":{75:11-75:14}:"%@"
anatofuz
parents:
diff changeset
80 }
anatofuz
parents:
diff changeset
81
anatofuz
parents:
diff changeset
82
anatofuz
parents:
diff changeset
83 typedef enum : int { NSUTF8StringEncoding = 8 } NSStringEncoding;
anatofuz
parents:
diff changeset
84 void test_fixed_enum_correction(NSStringEncoding x) {
anatofuz
parents:
diff changeset
85 NSLog(@"%@", x); // expected-warning{{format specifies type 'id' but the argument has underlying type 'int'}}
anatofuz
parents:
diff changeset
86 // CHECK: fix-it:"{{.*}}":{85:11-85:13}:"%d"
anatofuz
parents:
diff changeset
87 }
anatofuz
parents:
diff changeset
88
anatofuz
parents:
diff changeset
89 typedef __SIZE_TYPE__ size_t;
anatofuz
parents:
diff changeset
90 enum SomeSize : size_t { IntegerSize = sizeof(int) };
anatofuz
parents:
diff changeset
91 void test_named_fixed_enum_correction(enum SomeSize x) {
anatofuz
parents:
diff changeset
92 NSLog(@"%@", x); // expected-warning{{format specifies type 'id' but the argument has underlying type 'size_t' (aka}}
anatofuz
parents:
diff changeset
93 // CHECK: fix-it:"{{.*}}":{92:11-92:13}:"%zu"
anatofuz
parents:
diff changeset
94 }
anatofuz
parents:
diff changeset
95
anatofuz
parents:
diff changeset
96
anatofuz
parents:
diff changeset
97 typedef unsigned char uint8_t;
anatofuz
parents:
diff changeset
98 void test_char(char c, signed char s, unsigned char u, uint8_t n) {
anatofuz
parents:
diff changeset
99 NSLog(@"%s", c); // expected-warning{{format specifies type 'char *' but the argument has type 'char'}}
anatofuz
parents:
diff changeset
100 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%c"
anatofuz
parents:
diff changeset
101
anatofuz
parents:
diff changeset
102 NSLog(@"%lf", c); // expected-warning{{format specifies type 'double' but the argument has type 'char'}}
anatofuz
parents:
diff changeset
103 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:14}:"%c"
anatofuz
parents:
diff changeset
104
anatofuz
parents:
diff changeset
105 NSLog(@"%@", c); // expected-warning{{format specifies type 'id' but the argument has type 'char'}}
anatofuz
parents:
diff changeset
106 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%c"
anatofuz
parents:
diff changeset
107
anatofuz
parents:
diff changeset
108 NSLog(@"%c", c); // no-warning
anatofuz
parents:
diff changeset
109 // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%c"
anatofuz
parents:
diff changeset
110
anatofuz
parents:
diff changeset
111
anatofuz
parents:
diff changeset
112 NSLog(@"%s", s); // expected-warning{{format specifies type 'char *' but the argument has type 'signed char'}}
anatofuz
parents:
diff changeset
113 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%c"
anatofuz
parents:
diff changeset
114
anatofuz
parents:
diff changeset
115 NSLog(@"%lf", s); // expected-warning{{format specifies type 'double' but the argument has type 'signed char'}}
anatofuz
parents:
diff changeset
116 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:14}:"%c"
anatofuz
parents:
diff changeset
117
anatofuz
parents:
diff changeset
118 NSLog(@"%@", s); // expected-warning{{format specifies type 'id' but the argument has type 'signed char'}}
anatofuz
parents:
diff changeset
119 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%c"
anatofuz
parents:
diff changeset
120
anatofuz
parents:
diff changeset
121 NSLog(@"%c", s); // no-warning
anatofuz
parents:
diff changeset
122 // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%c"
anatofuz
parents:
diff changeset
123
anatofuz
parents:
diff changeset
124
anatofuz
parents:
diff changeset
125 NSLog(@"%s", u); // expected-warning{{format specifies type 'char *' but the argument has type 'unsigned char'}}
anatofuz
parents:
diff changeset
126 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%c"
anatofuz
parents:
diff changeset
127
anatofuz
parents:
diff changeset
128 NSLog(@"%lf", u); // expected-warning{{format specifies type 'double' but the argument has type 'unsigned char'}}
anatofuz
parents:
diff changeset
129 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:14}:"%c"
anatofuz
parents:
diff changeset
130
anatofuz
parents:
diff changeset
131 NSLog(@"%@", u); // expected-warning{{format specifies type 'id' but the argument has type 'unsigned char'}}
anatofuz
parents:
diff changeset
132 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%c"
anatofuz
parents:
diff changeset
133
anatofuz
parents:
diff changeset
134 NSLog(@"%c", u); // no-warning
anatofuz
parents:
diff changeset
135 // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%c"
anatofuz
parents:
diff changeset
136
anatofuz
parents:
diff changeset
137
anatofuz
parents:
diff changeset
138 NSLog(@"%s", n); // expected-warning{{format specifies type 'char *' but the argument has type 'uint8_t' (aka 'unsigned char')}}
anatofuz
parents:
diff changeset
139 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%hhu"
anatofuz
parents:
diff changeset
140
anatofuz
parents:
diff changeset
141 NSLog(@"%lf", n); // expected-warning{{format specifies type 'double' but the argument has type 'uint8_t' (aka 'unsigned char')}}
anatofuz
parents:
diff changeset
142 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:14}:"%hhu"
anatofuz
parents:
diff changeset
143
anatofuz
parents:
diff changeset
144 NSLog(@"%@", n); // expected-warning{{format specifies type 'id' but the argument has type 'uint8_t' (aka 'unsigned char')}}
anatofuz
parents:
diff changeset
145 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%hhu"
anatofuz
parents:
diff changeset
146
anatofuz
parents:
diff changeset
147 NSLog(@"%c", n); // no-warning
anatofuz
parents:
diff changeset
148 // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%hhu"
anatofuz
parents:
diff changeset
149
anatofuz
parents:
diff changeset
150
anatofuz
parents:
diff changeset
151 NSLog(@"%s", 'a'); // expected-warning{{format specifies type 'char *' but the argument has type 'char'}}
anatofuz
parents:
diff changeset
152 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%c"
anatofuz
parents:
diff changeset
153
anatofuz
parents:
diff changeset
154 NSLog(@"%lf", 'a'); // expected-warning{{format specifies type 'double' but the argument has type 'char'}}
anatofuz
parents:
diff changeset
155 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:14}:"%c"
anatofuz
parents:
diff changeset
156
anatofuz
parents:
diff changeset
157 NSLog(@"%@", 'a'); // expected-warning{{format specifies type 'id' but the argument has type 'char'}}
anatofuz
parents:
diff changeset
158 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%c"
anatofuz
parents:
diff changeset
159
anatofuz
parents:
diff changeset
160 NSLog(@"%c", 'a'); // no-warning
anatofuz
parents:
diff changeset
161 // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%c"
anatofuz
parents:
diff changeset
162
anatofuz
parents:
diff changeset
163
anatofuz
parents:
diff changeset
164 NSLog(@"%s", 'abcd'); // expected-warning{{format specifies type 'char *' but the argument has type 'int'}}
anatofuz
parents:
diff changeset
165 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%d"
anatofuz
parents:
diff changeset
166
anatofuz
parents:
diff changeset
167 NSLog(@"%lf", 'abcd'); // expected-warning{{format specifies type 'double' but the argument has type 'int'}}
anatofuz
parents:
diff changeset
168 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:14}:"%d"
anatofuz
parents:
diff changeset
169
anatofuz
parents:
diff changeset
170 NSLog(@"%@", 'abcd'); // expected-warning{{format specifies type 'id' but the argument has type 'int'}}
anatofuz
parents:
diff changeset
171 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%d"
anatofuz
parents:
diff changeset
172 }
anatofuz
parents:
diff changeset
173
anatofuz
parents:
diff changeset
174 void multichar_constants_false_negative() {
anatofuz
parents:
diff changeset
175 // The value of a multi-character constant is implementation-defined, but
anatofuz
parents:
diff changeset
176 // almost certainly shouldn't be printed with %c. However, the current
anatofuz
parents:
diff changeset
177 // type-checker expects %c to correspond to an integer argument, because
anatofuz
parents:
diff changeset
178 // many C library functions like fgetc() actually return an int (using -1
anatofuz
parents:
diff changeset
179 // as a sentinel).
anatofuz
parents:
diff changeset
180 NSLog(@"%c", 'abcd'); // missing-warning{{format specifies type 'char' but the argument has type 'int'}}
anatofuz
parents:
diff changeset
181 // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%d"
anatofuz
parents:
diff changeset
182 }
anatofuz
parents:
diff changeset
183
anatofuz
parents:
diff changeset
184
anatofuz
parents:
diff changeset
185 void test_percent_C() {
anatofuz
parents:
diff changeset
186 const unsigned short data = 'a';
anatofuz
parents:
diff changeset
187 NSLog(@"%C", data); // no-warning
anatofuz
parents:
diff changeset
188
anatofuz
parents:
diff changeset
189 NSLog(@"%C", 0x260300); // expected-warning{{format specifies type 'unichar' (aka 'unsigned short') but the argument has type 'int'}}
anatofuz
parents:
diff changeset
190 // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%d"
anatofuz
parents:
diff changeset
191 // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:16-[[@LINE-2]]:16}:"(unsigned short)"
anatofuz
parents:
diff changeset
192
anatofuz
parents:
diff changeset
193 typedef unsigned short unichar;
anatofuz
parents:
diff changeset
194
anatofuz
parents:
diff changeset
195 NSLog(@"%C", 0x260300); // expected-warning{{format specifies type 'unichar' (aka 'unsigned short') but the argument has type 'int'}}
anatofuz
parents:
diff changeset
196 // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%d"
anatofuz
parents:
diff changeset
197 // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:16-[[@LINE-2]]:16}:"(unichar)"
anatofuz
parents:
diff changeset
198
anatofuz
parents:
diff changeset
199 NSLog(@"%C", data ? 0x2F0000 : 0x260300); // expected-warning{{format specifies type 'unichar' (aka 'unsigned short') but the argument has type 'int'}}
anatofuz
parents:
diff changeset
200 // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%d"
anatofuz
parents:
diff changeset
201 // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:16-[[@LINE-2]]:16}:"(unichar)("
anatofuz
parents:
diff changeset
202 // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:42-[[@LINE-3]]:42}:")"
anatofuz
parents:
diff changeset
203
anatofuz
parents:
diff changeset
204 NSLog(@"%C", 0.0); // expected-warning{{format specifies type 'unichar' (aka 'unsigned short') but the argument has type 'double'}}
anatofuz
parents:
diff changeset
205 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%f"
anatofuz
parents:
diff changeset
206 // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-2]]:16-[[@LINE-2]]:16}:"(unichar)"
anatofuz
parents:
diff changeset
207
anatofuz
parents:
diff changeset
208 NSLog(@"%C", (char)0x260300);
anatofuz
parents:
diff changeset
209
anatofuz
parents:
diff changeset
210 NSLog(@"%C", 'a'); // expected-warning{{format specifies type 'unichar' (aka 'unsigned short') but the argument has type 'char'}}
anatofuz
parents:
diff changeset
211 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%c"
anatofuz
parents:
diff changeset
212 // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-2]]:16-[[@LINE-2]]:22}:"(unichar)"
anatofuz
parents:
diff changeset
213 }
anatofuz
parents:
diff changeset
214
anatofuz
parents:
diff changeset
215
anatofuz
parents:
diff changeset
216 void testSignedness(long i, unsigned long u) {
anatofuz
parents:
diff changeset
217 printf("%d", u); // expected-warning{{format specifies type 'int' but the argument has type 'unsigned long'}}
anatofuz
parents:
diff changeset
218 printf("%i", u); // expected-warning{{format specifies type 'int' but the argument has type 'unsigned long'}}
anatofuz
parents:
diff changeset
219 printf("%u", i); // expected-warning{{format specifies type 'unsigned int' but the argument has type 'long'}}
anatofuz
parents:
diff changeset
220
anatofuz
parents:
diff changeset
221 // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:11-[[@LINE-4]]:13}:"%lu"
anatofuz
parents:
diff changeset
222 // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:11-[[@LINE-4]]:13}:"%lu"
anatofuz
parents:
diff changeset
223 // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:11-[[@LINE-4]]:13}:"%ld"
anatofuz
parents:
diff changeset
224
anatofuz
parents:
diff changeset
225 printf("%+d", u); // expected-warning{{format specifies type 'int' but the argument has type 'unsigned long'}}
anatofuz
parents:
diff changeset
226
anatofuz
parents:
diff changeset
227 // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:11-[[@LINE-2]]:14}:"%+ld"
anatofuz
parents:
diff changeset
228 }
anatofuz
parents:
diff changeset
229
anatofuz
parents:
diff changeset
230 void testSizeTypes() {
anatofuz
parents:
diff changeset
231 printf("%zu", 0.f); // expected-warning-re{{format specifies type 'size_t' (aka '{{.+}}') but the argument has type 'float'}}
anatofuz
parents:
diff changeset
232 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:14}:"%f"
anatofuz
parents:
diff changeset
233
anatofuz
parents:
diff changeset
234 printf("%zd", 0.f); // expected-warning-re{{format specifies type 'ssize_t' (aka '{{.+}}') but the argument has type 'float'}}
anatofuz
parents:
diff changeset
235 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:14}:"%f"
anatofuz
parents:
diff changeset
236
anatofuz
parents:
diff changeset
237 short x;
anatofuz
parents:
diff changeset
238 printf("%zn", &x); // expected-warning-re{{format specifies type 'ssize_t *' (aka '{{.+}}') but the argument has type 'short *'}}
anatofuz
parents:
diff changeset
239 // PrintfSpecifier::fixType doesn't handle %n, so a fix-it is not emitted,
anatofuz
parents:
diff changeset
240 // see the comment in PrintfSpecifier::fixType in PrintfFormatString.cpp.
anatofuz
parents:
diff changeset
241 }
anatofuz
parents:
diff changeset
242
anatofuz
parents:
diff changeset
243 typedef __PTRDIFF_TYPE__ ptrdiff_t;
anatofuz
parents:
diff changeset
244 #define __UNSIGNED_PTRDIFF_TYPE__ \
anatofuz
parents:
diff changeset
245 __typeof__(_Generic((__PTRDIFF_TYPE__)0, \
anatofuz
parents:
diff changeset
246 long long int : (unsigned long long int)0, \
anatofuz
parents:
diff changeset
247 long int : (unsigned long int)0, \
anatofuz
parents:
diff changeset
248 int : (unsigned int)0, \
anatofuz
parents:
diff changeset
249 short : (unsigned short)0, \
anatofuz
parents:
diff changeset
250 signed char : (unsigned char)0))
anatofuz
parents:
diff changeset
251
anatofuz
parents:
diff changeset
252 void testPtrDiffTypes() {
anatofuz
parents:
diff changeset
253 __UNSIGNED_PTRDIFF_TYPE__ p1 = 0;
anatofuz
parents:
diff changeset
254 printf("%tu", p1); // No warning.
anatofuz
parents:
diff changeset
255
anatofuz
parents:
diff changeset
256 printf("%tu", 0.f); // expected-warning-re{{format specifies type 'unsigned ptrdiff_t' (aka '{{.+}}') but the argument has type 'float'}}
anatofuz
parents:
diff changeset
257 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:14}:"%f"
anatofuz
parents:
diff changeset
258
anatofuz
parents:
diff changeset
259 ptrdiff_t p2 = 0;
anatofuz
parents:
diff changeset
260 printf("%td", p2); // No warning.
anatofuz
parents:
diff changeset
261
anatofuz
parents:
diff changeset
262 printf("%td", 0.f); // expected-warning-re{{format specifies type 'ptrdiff_t' (aka '{{.+}}') but the argument has type 'float'}}
anatofuz
parents:
diff changeset
263 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:14}:"%f"
anatofuz
parents:
diff changeset
264
anatofuz
parents:
diff changeset
265 ptrdiff_t p3 = 0;
anatofuz
parents:
diff changeset
266 printf("%tn", &p3); // No warning.
anatofuz
parents:
diff changeset
267
anatofuz
parents:
diff changeset
268 short x;
anatofuz
parents:
diff changeset
269 printf("%tn", &x); // expected-warning-re{{format specifies type 'ptrdiff_t *' (aka '{{.+}}') but the argument has type 'short *'}}
anatofuz
parents:
diff changeset
270 // PrintfSpecifier::fixType doesn't handle %n, so a fix-it is not emitted,
anatofuz
parents:
diff changeset
271 // see the comment in PrintfSpecifier::fixType in PrintfFormatString.cpp.
anatofuz
parents:
diff changeset
272 }
anatofuz
parents:
diff changeset
273
anatofuz
parents:
diff changeset
274 void testEnum() {
anatofuz
parents:
diff changeset
275 typedef enum {
anatofuz
parents:
diff changeset
276 ImplicitA = 1,
anatofuz
parents:
diff changeset
277 ImplicitB = 2
anatofuz
parents:
diff changeset
278 } Implicit;
anatofuz
parents:
diff changeset
279
anatofuz
parents:
diff changeset
280 typedef enum {
anatofuz
parents:
diff changeset
281 ImplicitLLA = 0,
anatofuz
parents:
diff changeset
282 ImplicitLLB = ~0ULL
anatofuz
parents:
diff changeset
283 } ImplicitLongLong;
anatofuz
parents:
diff changeset
284
anatofuz
parents:
diff changeset
285 typedef enum : short {
anatofuz
parents:
diff changeset
286 ExplicitA = 0,
anatofuz
parents:
diff changeset
287 ExplicitB
anatofuz
parents:
diff changeset
288 } ExplicitShort;
anatofuz
parents:
diff changeset
289
anatofuz
parents:
diff changeset
290 printf("%f", (Implicit)0); // expected-warning{{format specifies type 'double' but the argument has underlying type}}
anatofuz
parents:
diff changeset
291 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%{{[du]}}"
anatofuz
parents:
diff changeset
292
anatofuz
parents:
diff changeset
293 printf("%f", (ImplicitLongLong)0); // expected-warning{{format specifies type 'double' but the argument has underlying type}}
anatofuz
parents:
diff changeset
294 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%{{l*[du]}}"
anatofuz
parents:
diff changeset
295
anatofuz
parents:
diff changeset
296 printf("%f", (ExplicitShort)0); // expected-warning{{format specifies type 'double' but the argument has underlying type 'short'}}
anatofuz
parents:
diff changeset
297 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%hd"
anatofuz
parents:
diff changeset
298 }