Switch the token-paste source locations inside of function style macro
argument expansion to use the macro argument source locations as well.
Add a few tests to exercise this. There is still a bit more work needed
here though.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@134674 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Lex/TokenLexer.cpp b/lib/Lex/TokenLexer.cpp
index fac6b7d..8aa2c79 100644
--- a/lib/Lex/TokenLexer.cpp
+++ b/lib/Lex/TokenLexer.cpp
@@ -289,9 +289,9 @@
for (unsigned i = ResultToks.size() - NumToks, e = ResultToks.size();
i != e; ++i) {
Token &Tok = ResultToks[i];
- Tok.setLocation(SM.createInstantiationLoc(Tok.getLocation(),
- curInst, curInst,
- Tok.getLength()));
+ Tok.setLocation(SM.createMacroArgInstantiationLoc(Tok.getLocation(),
+ curInst,
+ Tok.getLength()));
}
}
diff --git a/test/Misc/caret-diags-macros.c b/test/Misc/caret-diags-macros.c
index a703618..66d16a2 100644
--- a/test/Misc/caret-diags-macros.c
+++ b/test/Misc/caret-diags-macros.c
@@ -84,3 +84,40 @@
// CHECK: {{.*}}:39:55: note: instantiated from:
// CHECK: {{.*}}:38:35: note: instantiated from:
}
+
+#define variadic_args1(x, y, ...) y
+#define variadic_args2(x, ...) variadic_args1(x, __VA_ARGS__)
+#define variadic_args3(x, y, ...) variadic_args2(x, y, __VA_ARGS__)
+
+void test2() {
+ variadic_args3(1, 2, 3, 4);
+ // CHECK: {{.*}}:93:21: warning: expression result unused
+ // CHECK-NEXT: variadic_args3(1, 2, 3, 4);
+ // CHECK-NEXT: ~~~~~~~~~~~~~~~~~~^~~~~~~~
+ // CHECK: {{.*}}:90:53: note: instantiated from:
+ // CHECK: {{.*}}:89:50: note: instantiated from:
+ // CHECK: {{.*}}:88:35: note: instantiated from:
+}
+
+#define variadic_pasting_args1(x, y, z) y
+#define variadic_pasting_args2(x, ...) variadic_pasting_args1(x ## __VA_ARGS__)
+#define variadic_pasting_args2a(x, y, ...) variadic_pasting_args1(x, y ## __VA_ARGS__)
+#define variadic_pasting_args3(x, y, ...) variadic_pasting_args2(x, y, __VA_ARGS__)
+#define variadic_pasting_args3a(x, y, ...) variadic_pasting_args2a(x, y, __VA_ARGS__)
+
+void test3() {
+ variadic_pasting_args3(1, 2, 3, 4);
+ // CHECK: {{.*}}:109:32: warning: expression result unused
+ // CHECK: {{.*}}:105:72: note: instantiated from:
+ // CHECK: {{.*}}:103:68: note: instantiated from:
+ // CHECK: {{.*}}:102:41: note: instantiated from:
+
+ variadic_pasting_args3a(1, 2, 3, 4);
+ // FIXME: It'd be really nice to retain the start location of the first token
+ // involved in the token paste instead of falling back on the full macro
+ // location in the first two locations here.
+ // CHECK: {{.*}}:115:3: warning: expression result unused
+ // CHECK: {{.*}}:106:44: note: instantiated from:
+ // CHECK: {{.*}}:104:72: note: instantiated from:
+ // CHECK: {{.*}}:102:41: note: instantiated from:
+}