• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// RUN: %clang_cc1 -fsyntax-only -fblocks -verify %s
2// RUN: %clang_cc1 -fdiagnostics-parseable-fixits -fblocks %s 2>&1 | FileCheck %s
3
4@class NSString;
5extern void NSLog(NSString *, ...);
6int printf(const char * restrict, ...) ;
7
8void test_integer_correction (int x) {
9  printf("%d", x); // no-warning
10  printf("%s", x); // expected-warning{{format specifies type 'char *' but the argument has type 'int'}}
11  printf("%lf", x); // expected-warning{{format specifies type 'double' but the argument has type 'int'}}
12  // CHECK: fix-it:"{{.*}}":{10:11-10:13}:"%d"
13  // CHECK: fix-it:"{{.*}}":{11:11-11:14}:"%d"
14
15  NSLog(@"%d", x); // no-warning
16  NSLog(@"%s", x); // expected-warning{{format specifies type 'char *' but the argument has type 'int'}}
17  NSLog(@"%lf", x); // expected-warning{{format specifies type 'double' but the argument has type 'int'}}
18  NSLog(@"%@", x); // expected-warning{{format specifies type 'id' but the argument has type 'int'}}
19  // CHECK: fix-it:"{{.*}}":{16:11-16:13}:"%d"
20  // CHECK: fix-it:"{{.*}}":{17:11-17:14}:"%d"
21  // CHECK: fix-it:"{{.*}}":{18:11-18:13}:"%d"
22}
23
24void test_string_correction (char *x) {
25  printf("%d", x); // expected-warning{{format specifies type 'int' but the argument has type 'char *'}}
26  printf("%s", x); // no-warning
27  printf("%lf", x); // expected-warning{{format specifies type 'double' but the argument has type 'char *'}}
28  // CHECK: fix-it:"{{.*}}":{25:11-25:13}:"%s"
29  // CHECK: fix-it:"{{.*}}":{27:11-27:14}:"%s"
30
31  NSLog(@"%d", x); // expected-warning{{format specifies type 'int' but the argument has type 'char *'}}
32  NSLog(@"%s", x); // no-warning
33  NSLog(@"%lf", x); // expected-warning{{format specifies type 'double' but the argument has type 'char *'}}
34  NSLog(@"%@", x); // expected-warning{{format specifies type 'id' but the argument has type 'char *'}}
35  // CHECK: fix-it:"{{.*}}":{31:11-31:13}:"%s"
36  // CHECK: fix-it:"{{.*}}":{33:11-33:14}:"%s"
37  // CHECK: fix-it:"{{.*}}":{34:11-34:13}:"%s"
38}
39
40void test_object_correction (id x) {
41  NSLog(@"%d", x); // expected-warning{{format specifies type 'int' but the argument has type 'id'}}
42  NSLog(@"%s", x); // expected-warning{{format specifies type 'char *' but the argument has type 'id'}}
43  NSLog(@"%lf", x); // expected-warning{{format specifies type 'double' but the argument has type 'id'}}
44  NSLog(@"%@", x); // no-warning
45  // CHECK: fix-it:"{{.*}}":{41:11-41:13}:"%@"
46  // CHECK: fix-it:"{{.*}}":{42:11-42:13}:"%@"
47  // CHECK: fix-it:"{{.*}}":{43:11-43:14}:"%@"
48}
49
50typedef const struct __CFString * __attribute__((NSObject)) CFStringRef;
51void test_cf_object_correction (CFStringRef x) {
52  NSLog(@"%d", x); // expected-warning{{format specifies type 'int' but the argument has type 'CFStringRef'}}
53  NSLog(@"%s", x); // expected-warning{{format specifies type 'char *' but the argument has type 'CFStringRef'}}
54  NSLog(@"%lf", x); // expected-warning{{format specifies type 'double' but the argument has type 'CFStringRef'}}
55  NSLog(@"%@", x); // no-warning
56  // CHECK: fix-it:"{{.*}}":{52:11-52:13}:"%@"
57  // CHECK: fix-it:"{{.*}}":{53:11-53:13}:"%@"
58  // CHECK: fix-it:"{{.*}}":{54:11-54:14}:"%@"
59}
60
61typedef void (^block_t)(void);
62void test_block_correction (block_t x) {
63  NSLog(@"%d", x); // expected-warning{{format specifies type 'int' but the argument has type 'block_t'}}
64  NSLog(@"%s", x); // expected-warning{{format specifies type 'char *' but the argument has type 'block_t'}}
65  NSLog(@"%lf", x); // expected-warning{{format specifies type 'double' but the argument has type 'block_t'}}
66  NSLog(@"%@", x); // no-warning
67  // CHECK: fix-it:"{{.*}}":{63:11-63:13}:"%@"
68  // CHECK: fix-it:"{{.*}}":{64:11-64:13}:"%@"
69  // CHECK: fix-it:"{{.*}}":{65:11-65:14}:"%@"
70}
71
72void test_class_correction (Class x) {
73  NSLog(@"%d", x); // expected-warning{{format specifies type 'int' but the argument has type 'Class'}}
74  NSLog(@"%s", x); // expected-warning{{format specifies type 'char *' but the argument has type 'Class'}}
75  NSLog(@"%lf", x); // expected-warning{{format specifies type 'double' but the argument has type 'Class'}}
76  NSLog(@"%@", x); // no-warning
77  // CHECK: fix-it:"{{.*}}":{73:11-73:13}:"%@"
78  // CHECK: fix-it:"{{.*}}":{74:11-74:13}:"%@"
79  // CHECK: fix-it:"{{.*}}":{75:11-75:14}:"%@"
80}
81
82
83typedef enum : int { NSUTF8StringEncoding = 8 } NSStringEncoding;
84void test_fixed_enum_correction(NSStringEncoding x) {
85  NSLog(@"%@", x); // expected-warning{{format specifies type 'id' but the argument has type 'NSStringEncoding'}}
86  // CHECK: fix-it:"{{.*}}":{85:11-85:13}:"%d"
87}
88
89typedef __SIZE_TYPE__ size_t;
90enum SomeSize : size_t { IntegerSize = sizeof(int) };
91void test_named_fixed_enum_correction(enum SomeSize x) {
92  NSLog(@"%@", x); // expected-warning{{format specifies type 'id' but the argument has type 'enum SomeSize'}}
93  // CHECK: fix-it:"{{.*}}":{92:11-92:13}:"%zu"
94}
95
96