1 | // RUN: cp %s %t |
2 | // RUN: %clang_cc1 -triple x86_64-apple-darwin9 -fsyntax-only -fblocks -Wformat -fixit %t |
3 | // RUN: grep -v CHECK %t | FileCheck %s |
4 | |
5 | /* This is a test of code modifications created by darwin format fix-its hints |
6 | that are provided as part of warning */ |
7 | |
8 | int printf(const char * restrict, ...); |
9 | |
10 | #if __LP64__ |
11 | typedef long CFIndex; |
12 | typedef long NSInteger; |
13 | typedef unsigned long NSUInteger; |
14 | #else |
15 | typedef int CFIndex; |
16 | typedef int NSInteger; |
17 | typedef unsigned int NSUInteger; |
18 | #endif |
19 | CFIndex getCFIndex(); |
20 | NSInteger getNSInteger(); |
21 | NSUInteger getNSUInteger(); |
22 | |
23 | #define Log1(...) \ |
24 | do { \ |
25 | printf(__VA_ARGS__); \ |
26 | } while (0) |
27 | |
28 | #define Log2(...) \ |
29 | do { \ |
30 | printf(__VA_ARGS__); \ |
31 | printf(__VA_ARGS__); \ |
32 | } while (0) \ |
33 | |
34 | #define Log3(X, Y, Z) \ |
35 | do { \ |
36 | printf(X, Y); \ |
37 | printf(X, Z); \ |
38 | } while (0) \ |
39 | |
40 | void test() { |
41 | printf("test 1: %s", getNSInteger()); |
42 | // CHECK: printf("test 1: %ld", (long)getNSInteger()); |
43 | printf("test 2: %s %s", getNSInteger(), getNSInteger()); |
44 | // CHECK: printf("test 2: %ld %ld", (long)getNSInteger(), (long)getNSInteger()); |
45 | |
46 | Log1("test 3: %s", getNSInteger()); |
47 | // CHECK: Log1("test 3: %ld", (long)getNSInteger()); |
48 | Log1("test 4: %s %s", getNSInteger(), getNSInteger()); |
49 | // CHECK: Log1("test 4: %ld %ld", (long)getNSInteger(), (long)getNSInteger()); |
50 | |
51 | Log2("test 5: %s", getNSInteger()); |
52 | // CHECK: Log2("test 5: %ld", (long)getNSInteger()); |
53 | Log2("test 6: %s %s", getNSInteger(), getNSInteger()); |
54 | // CHECK: Log2("test 6: %ld %ld", (long)getNSInteger(), (long)getNSInteger()); |
55 | |
56 | // Artificial test to check that X (in Log3(X, Y, Z)) |
57 | // is modified only according to the diagnostics |
58 | // for the first printf and the modification caused |
59 | // by the second printf is dropped. |
60 | Log3("test 7: %s", getNSInteger(), getNSUInteger()); |
61 | // CHECK: Log3("test 7: %ld", (long)getNSInteger(), (unsigned long)getNSUInteger()); |
62 | } |
63 | |
64 | #define Outer1(...) \ |
65 | do { \ |
66 | printf(__VA_ARGS__); \ |
67 | } while (0) |
68 | |
69 | #define Outer2(...) \ |
70 | do { \ |
71 | Outer1(__VA_ARGS__); Outer1(__VA_ARGS__); \ |
72 | } while (0) |
73 | |
74 | void bug33447() { |
75 | Outer2("test 8: %s", getNSInteger()); |
76 | // CHECK: Outer2("test 8: %ld", (long)getNSInteger()); |
77 | Outer2("test 9: %s %s", getNSInteger(), getNSInteger()); |
78 | // CHECK: Outer2("test 9: %ld %ld", (long)getNSInteger(), (long)getNSInteger()); |
79 | } |
80 | |
81 | void testCFIndex() { |
82 | printf("test 10: %s", getCFIndex()); |
83 | // CHECK: printf("test 10: %ld", (long)getCFIndex()); |
84 | printf("test 11: %s %s", getCFIndex(), getCFIndex()); |
85 | // CHECK: printf("test 11: %ld %ld", (long)getCFIndex(), (long)getCFIndex()); |
86 | } |
87 | |