Chandler Carruth | 60be4de | 2011-03-09 10:56:54 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only %s 2>&1 | FileCheck %s |
Chris Lattner | 037fb7f | 2009-05-05 22:03:18 +0000 | [diff] [blame] | 2 | |
| 3 | #define M1(x) x |
Chris Lattner | 037fb7f | 2009-05-05 22:03:18 +0000 | [diff] [blame] | 4 | #define M2 1; |
Chris Lattner | 037fb7f | 2009-05-05 22:03:18 +0000 | [diff] [blame] | 5 | void foo() { |
Chandler Carruth | 60be4de | 2011-03-09 10:56:54 +0000 | [diff] [blame] | 6 | M1( |
| 7 | M2); |
Chandler Carruth | c8d1ecc | 2011-07-07 23:56:36 +0000 | [diff] [blame] | 8 | // CHECK: :7:{{[0-9]+}}: warning: expression result unused |
Chandler Carruth | 4e80546 | 2011-07-14 08:20:28 +0000 | [diff] [blame] | 9 | // CHECK: :4:{{[0-9]+}}: note: expanded from: |
| 10 | // CHECK: :3:{{[0-9]+}}: note: expanded from: |
Chris Lattner | 037fb7f | 2009-05-05 22:03:18 +0000 | [diff] [blame] | 11 | } |
| 12 | |
Chris Lattner | 037fb7f | 2009-05-05 22:03:18 +0000 | [diff] [blame] | 13 | #define A 1 |
Chris Lattner | 037fb7f | 2009-05-05 22:03:18 +0000 | [diff] [blame] | 14 | #define B A |
Chris Lattner | 037fb7f | 2009-05-05 22:03:18 +0000 | [diff] [blame] | 15 | #define C B |
Chris Lattner | 037fb7f | 2009-05-05 22:03:18 +0000 | [diff] [blame] | 16 | void bar() { |
Chris Lattner | 037fb7f | 2009-05-05 22:03:18 +0000 | [diff] [blame] | 17 | C; |
Chris Lattner | 8306831 | 2011-06-28 05:11:33 +0000 | [diff] [blame] | 18 | // CHECK: :17:3: warning: expression result unused |
Chandler Carruth | 4e80546 | 2011-07-14 08:20:28 +0000 | [diff] [blame] | 19 | // CHECK: :15:11: note: expanded from: |
| 20 | // CHECK: :14:11: note: expanded from: |
| 21 | // CHECK: :13:11: note: expanded from: |
Chris Lattner | 037fb7f | 2009-05-05 22:03:18 +0000 | [diff] [blame] | 22 | } |
| 23 | |
Chris Lattner | a5c6c58 | 2010-02-12 19:31:35 +0000 | [diff] [blame] | 24 | // rdar://7597492 |
| 25 | #define sprintf(str, A, B) \ |
| 26 | __builtin___sprintf_chk (str, 0, 42, A, B) |
| 27 | |
| 28 | void baz(char *Msg) { |
| 29 | sprintf(Msg, " sizeof FoooLib : =%3u\n", 12LL); |
| 30 | } |
| 31 | |
Chris Lattner | 8306831 | 2011-06-28 05:11:33 +0000 | [diff] [blame] | 32 | |
Chandler Carruth | c8d1ecc | 2011-07-07 23:56:36 +0000 | [diff] [blame] | 33 | // PR9279: comprehensive tests for multi-level macro back traces |
| 34 | #define macro_args1(x) x |
| 35 | #define macro_args2(x) macro_args1(x) |
| 36 | #define macro_args3(x) macro_args2(x) |
Chris Lattner | 8306831 | 2011-06-28 05:11:33 +0000 | [diff] [blame] | 37 | |
Chandler Carruth | c8d1ecc | 2011-07-07 23:56:36 +0000 | [diff] [blame] | 38 | #define macro_many_args1(x, y, z) y |
| 39 | #define macro_many_args2(x, y, z) macro_many_args1(x, y, z) |
| 40 | #define macro_many_args3(x, y, z) macro_many_args2(x, y, z) |
Chris Lattner | 8306831 | 2011-06-28 05:11:33 +0000 | [diff] [blame] | 41 | |
Chandler Carruth | c8d1ecc | 2011-07-07 23:56:36 +0000 | [diff] [blame] | 42 | void test() { |
| 43 | macro_args3(1); |
| 44 | // CHECK: {{.*}}:43:15: warning: expression result unused |
| 45 | // Also check that the 'caret' printing agrees with the location here where |
| 46 | // its easy to FileCheck. |
| 47 | // CHECK-NEXT: macro_args3(1); |
| 48 | // CHECK-NEXT: ~~~~~~~~~~~~^~ |
Chandler Carruth | 4e80546 | 2011-07-14 08:20:28 +0000 | [diff] [blame] | 49 | // CHECK: {{.*}}:36:36: note: expanded from: |
| 50 | // CHECK: {{.*}}:35:36: note: expanded from: |
| 51 | // CHECK: {{.*}}:34:24: note: expanded from: |
Chandler Carruth | c8d1ecc | 2011-07-07 23:56:36 +0000 | [diff] [blame] | 52 | |
| 53 | macro_many_args3( |
| 54 | 1, |
| 55 | 2, |
| 56 | 3); |
| 57 | // CHECK: {{.*}}:55:5: warning: expression result unused |
Chandler Carruth | 4e80546 | 2011-07-14 08:20:28 +0000 | [diff] [blame] | 58 | // CHECK: {{.*}}:40:55: note: expanded from: |
| 59 | // CHECK: {{.*}}:39:55: note: expanded from: |
| 60 | // CHECK: {{.*}}:38:35: note: expanded from: |
Chandler Carruth | c8d1ecc | 2011-07-07 23:56:36 +0000 | [diff] [blame] | 61 | |
| 62 | macro_many_args3( |
| 63 | 1, |
| 64 | M2, |
| 65 | 3); |
| 66 | // CHECK: {{.*}}:64:5: warning: expression result unused |
Chandler Carruth | 4e80546 | 2011-07-14 08:20:28 +0000 | [diff] [blame] | 67 | // CHECK: {{.*}}:4:12: note: expanded from: |
| 68 | // CHECK: {{.*}}:40:55: note: expanded from: |
| 69 | // CHECK: {{.*}}:39:55: note: expanded from: |
| 70 | // CHECK: {{.*}}:38:35: note: expanded from: |
Chandler Carruth | c8d1ecc | 2011-07-07 23:56:36 +0000 | [diff] [blame] | 71 | |
| 72 | macro_many_args3( |
| 73 | 1, |
| 74 | macro_args2(2), |
| 75 | 3); |
| 76 | // CHECK: {{.*}}:74:17: warning: expression result unused |
| 77 | // This caret location needs to be printed *inside* a different macro's |
| 78 | // arguments. |
| 79 | // CHECK-NEXT: macro_args2(2), |
| 80 | // CHECK-NEXT: ~~~~~~~~~~~~^~~ |
Chandler Carruth | 4e80546 | 2011-07-14 08:20:28 +0000 | [diff] [blame] | 81 | // CHECK: {{.*}}:35:36: note: expanded from: |
| 82 | // CHECK: {{.*}}:34:24: note: expanded from: |
| 83 | // CHECK: {{.*}}:40:55: note: expanded from: |
| 84 | // CHECK: {{.*}}:39:55: note: expanded from: |
| 85 | // CHECK: {{.*}}:38:35: note: expanded from: |
Chandler Carruth | c8d1ecc | 2011-07-07 23:56:36 +0000 | [diff] [blame] | 86 | } |
Chandler Carruth | 886ea9b | 2011-07-08 01:04:21 +0000 | [diff] [blame] | 87 | |
| 88 | #define variadic_args1(x, y, ...) y |
| 89 | #define variadic_args2(x, ...) variadic_args1(x, __VA_ARGS__) |
| 90 | #define variadic_args3(x, y, ...) variadic_args2(x, y, __VA_ARGS__) |
| 91 | |
| 92 | void test2() { |
| 93 | variadic_args3(1, 2, 3, 4); |
| 94 | // CHECK: {{.*}}:93:21: warning: expression result unused |
| 95 | // CHECK-NEXT: variadic_args3(1, 2, 3, 4); |
| 96 | // CHECK-NEXT: ~~~~~~~~~~~~~~~~~~^~~~~~~~ |
Chandler Carruth | 4e80546 | 2011-07-14 08:20:28 +0000 | [diff] [blame] | 97 | // CHECK: {{.*}}:90:53: note: expanded from: |
| 98 | // CHECK: {{.*}}:89:50: note: expanded from: |
| 99 | // CHECK: {{.*}}:88:35: note: expanded from: |
Chandler Carruth | 886ea9b | 2011-07-08 01:04:21 +0000 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | #define variadic_pasting_args1(x, y, z) y |
| 103 | #define variadic_pasting_args2(x, ...) variadic_pasting_args1(x ## __VA_ARGS__) |
| 104 | #define variadic_pasting_args2a(x, y, ...) variadic_pasting_args1(x, y ## __VA_ARGS__) |
| 105 | #define variadic_pasting_args3(x, y, ...) variadic_pasting_args2(x, y, __VA_ARGS__) |
| 106 | #define variadic_pasting_args3a(x, y, ...) variadic_pasting_args2a(x, y, __VA_ARGS__) |
| 107 | |
| 108 | void test3() { |
| 109 | variadic_pasting_args3(1, 2, 3, 4); |
| 110 | // CHECK: {{.*}}:109:32: warning: expression result unused |
Chandler Carruth | 4e80546 | 2011-07-14 08:20:28 +0000 | [diff] [blame] | 111 | // CHECK: {{.*}}:105:72: note: expanded from: |
| 112 | // CHECK: {{.*}}:103:68: note: expanded from: |
| 113 | // CHECK: {{.*}}:102:41: note: expanded from: |
Chandler Carruth | 886ea9b | 2011-07-08 01:04:21 +0000 | [diff] [blame] | 114 | |
| 115 | variadic_pasting_args3a(1, 2, 3, 4); |
| 116 | // FIXME: It'd be really nice to retain the start location of the first token |
| 117 | // involved in the token paste instead of falling back on the full macro |
| 118 | // location in the first two locations here. |
| 119 | // CHECK: {{.*}}:115:3: warning: expression result unused |
Chandler Carruth | 4e80546 | 2011-07-14 08:20:28 +0000 | [diff] [blame] | 120 | // CHECK: {{.*}}:106:44: note: expanded from: |
| 121 | // CHECK: {{.*}}:104:72: note: expanded from: |
| 122 | // CHECK: {{.*}}:102:41: note: expanded from: |
Chandler Carruth | 886ea9b | 2011-07-08 01:04:21 +0000 | [diff] [blame] | 123 | } |