[cfe-commits] r134674 - in /cfe/trunk: lib/Lex/TokenLexer.cpp test/Misc/caret-diags-macros.c

Chandler Carruth chandlerc at gmail.com
Thu Jul 7 18:04:21 PDT 2011


Author: chandlerc
Date: Thu Jul  7 20:04:21 2011
New Revision: 134674

URL: http://llvm.org/viewvc/llvm-project?rev=134674&view=rev
Log:
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.

Modified:
    cfe/trunk/lib/Lex/TokenLexer.cpp
    cfe/trunk/test/Misc/caret-diags-macros.c

Modified: cfe/trunk/lib/Lex/TokenLexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/TokenLexer.cpp?rev=134674&r1=134673&r2=134674&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/TokenLexer.cpp (original)
+++ cfe/trunk/lib/Lex/TokenLexer.cpp Thu Jul  7 20:04:21 2011
@@ -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()));
         }
       }
 

Modified: cfe/trunk/test/Misc/caret-diags-macros.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/caret-diags-macros.c?rev=134674&r1=134673&r2=134674&view=diff
==============================================================================
--- cfe/trunk/test/Misc/caret-diags-macros.c (original)
+++ cfe/trunk/test/Misc/caret-diags-macros.c Thu Jul  7 20:04:21 2011
@@ -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:
+}





More information about the cfe-commits mailing list