]> granicus.if.org Git - clang/commitdiff
Switch the token-paste source locations inside of function style macro
authorChandler Carruth <chandlerc@gmail.com>
Fri, 8 Jul 2011 01:04:21 +0000 (01:04 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Fri, 8 Jul 2011 01:04:21 +0000 (01:04 +0000)
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

lib/Lex/TokenLexer.cpp
test/Misc/caret-diags-macros.c

index fac6b7dc3ea6d4450d58f9c0c2cd039fc7b37acd..8aa2c79ac30345fb2f5c9fcc431112117a09594d 100644 (file)
@@ -289,9 +289,9 @@ void TokenLexer::ExpandFunctionArguments() {
         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()));
         }
       }
 
index a70361820f96f09b8fbc1652863125244f15d45a..66d16a251b952d202b5fa9e2ce473fecf040bd39 100644 (file)
@@ -84,3 +84,40 @@ void test() {
   // 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:
+}