[cfe-commits] r72519 - /cfe/trunk/lib/Lex/TokenLexer.cpp

Chris Lattner sabre at nondot.org
Wed May 27 22:40:04 PDT 2009


Author: lattner
Date: Thu May 28 00:39:39 2009
New Revision: 72519

URL: http://llvm.org/viewvc/llvm-project?rev=72519&view=rev
Log:
fix the "pasting formed 'a]', an invalid preprocessing token"
diagnostic to include the full instantiation location for the
invalid paste.  For:

#define foo(a, b)  a ## b
#define bar(x) foo(x, ])
bar(a)
bar(zdy)

Instead of:

t.c:3:22: error: pasting formed 'a]', an invalid preprocessing token
#define foo(a, b)  a ## b
                     ^
t.c:3:22: error: pasting formed 'zdy]', an invalid preprocessing token

we now produce:

t.c:7:1: error: pasting formed 'a]', an invalid preprocessing token
bar(a)
^
t.c:4:16: note: instantiated from:
#define bar(x) foo(x, ])
               ^
t.c:3:22: note: instantiated from:
#define foo(a, b)  a ## b
                     ^
t.c:8:1: error: pasting formed 'zdy]', an invalid preprocessing token
bar(zdy)
^
t.c:4:16: note: instantiated from:
#define bar(x) foo(x, ])
               ^
t.c:3:22: note: instantiated from:
#define foo(a, b)  a ## b
                     ^


Modified:
    cfe/trunk/lib/Lex/TokenLexer.cpp

Modified: cfe/trunk/lib/Lex/TokenLexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/TokenLexer.cpp?rev=72519&r1=72518&r2=72519&view=diff

==============================================================================
--- cfe/trunk/lib/Lex/TokenLexer.cpp (original)
+++ cfe/trunk/lib/Lex/TokenLexer.cpp Thu May 28 00:39:39 2009
@@ -471,9 +471,16 @@
         }
       
         // Do not emit the warning when preprocessing assembler code.
-        if (!PP.getLangOptions().AsmPreprocessor)
-          PP.Diag(PasteOpLoc, diag::err_pp_bad_paste)
+        if (!PP.getLangOptions().AsmPreprocessor) {
+          // Explicitly convert the token location to have proper instantiation
+          // information so that the user knows where it came from.
+          SourceManager &SM = PP.getSourceManager();
+          SourceLocation Loc =
+            SM.createInstantiationLoc(PasteOpLoc, InstantiateLocStart,
+                                      InstantiateLocEnd, 2);
+          PP.Diag(Loc, diag::err_pp_bad_paste)
             << std::string(Buffer.begin(), Buffer.end());
+        }
         
         // Do not consume the RHS.
         --CurToken;





More information about the cfe-commits mailing list