[cfe-commits] r133005 - in /cfe/trunk: lib/Lex/TokenLexer.cpp test/Preprocessor/macro_paste_bad.c test/Preprocessor/macro_paste_simple.c

Chris Lattner sabre at nondot.org
Tue Jun 14 11:19:37 PDT 2011


Author: lattner
Date: Tue Jun 14 13:19:37 2011
New Revision: 133005

URL: http://llvm.org/viewvc/llvm-project?rev=133005&view=rev
Log:
revert r133003 and fix the bug properly: the issue was that ## in a token
lexer is not a paste operator, it is a normal token.  This fixes a conformance
issue shown here:
http://p99.gforge.inria.fr/c99-conformance/c99-conformance-clang-2.9.html

and it defines away the crash from before.


Modified:
    cfe/trunk/lib/Lex/TokenLexer.cpp
    cfe/trunk/test/Preprocessor/macro_paste_bad.c
    cfe/trunk/test/Preprocessor/macro_paste_simple.c

Modified: cfe/trunk/lib/Lex/TokenLexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/TokenLexer.cpp?rev=133005&r1=133004&r2=133005&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/TokenLexer.cpp (original)
+++ cfe/trunk/lib/Lex/TokenLexer.cpp Tue Jun 14 13:19:37 2011
@@ -327,7 +327,8 @@
   bool TokenIsFromPaste = false;
 
   // If this token is followed by a token paste (##) operator, paste the tokens!
-  if (!isAtEnd() && Tokens[CurToken].is(tok::hashhash)) {
+  // Note that ## is a normal token when not expanding a macro.
+  if (!isAtEnd() && Tokens[CurToken].is(tok::hashhash) && Macro) {
     // When handling the microsoft /##/ extension, the final token is
     // returned by PasteTokens, not the pasted token.
     if (PasteTokens(Tok))
@@ -487,10 +488,9 @@
           // 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 = PasteOpLoc;
-          if (InstantiateLocStart.isValid())
-            Loc = SM.createInstantiationLoc(Loc, InstantiateLocStart,
-                                            InstantiateLocEnd, 2);
+          SourceLocation Loc =
+            SM.createInstantiationLoc(PasteOpLoc, InstantiateLocStart,
+                                      InstantiateLocEnd, 2);
           // If we're in microsoft extensions mode, downgrade this from a hard
           // error to a warning that defaults to an error.  This allows
           // disabling it.

Modified: cfe/trunk/test/Preprocessor/macro_paste_bad.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/macro_paste_bad.c?rev=133005&r1=133004&r2=133005&view=diff
==============================================================================
--- cfe/trunk/test/Preprocessor/macro_paste_bad.c (original)
+++ cfe/trunk/test/Preprocessor/macro_paste_bad.c Tue Jun 14 13:19:37 2011
@@ -32,10 +32,3 @@
 #define VA __VA_ ## ARGS__
 int VA;   // expected-warning {{__VA_ARGS__ can only appear in the expansion of a C99 variadic macro}}
 
-
-// PR9981
-#define M1(A) A
-#define M2(X) 
-M1(M2(##))   // expected-error {{pasting formed '()', an invalid preprocessing token}}
-
-

Modified: cfe/trunk/test/Preprocessor/macro_paste_simple.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/macro_paste_simple.c?rev=133005&r1=133004&r2=133005&view=diff
==============================================================================
--- cfe/trunk/test/Preprocessor/macro_paste_simple.c (original)
+++ cfe/trunk/test/Preprocessor/macro_paste_simple.c Tue Jun 14 13:19:37 2011
@@ -1,5 +1,14 @@
-// RUN: %clang_cc1 %s -E | grep "barbaz123"
+// RUN: %clang_cc1 %s -E | FileCheck %s
 
 #define FOO bar ## baz ## 123
 
-FOO
+// CHECK: A: barbaz123
+A: FOO
+
+// PR9981
+#define M1(A) A
+#define M2(X) X
+B: M1(M2(##))
+
+// CHECK: B: ##
+





More information about the cfe-commits mailing list