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

Chris Lattner sabre at nondot.org
Sun Apr 19 13:29:43 PDT 2009


Author: lattner
Date: Sun Apr 19 15:29:42 2009
New Revision: 69544

URL: http://llvm.org/viewvc/llvm-project?rev=69544&view=rev
Log:
move token paste poisoning diagnostics to after the instantiation loc
for a token is set, this makes the diagnostic "expanded from stack" work
for this diagnostic.  Add a testcase for PR3918.


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

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

==============================================================================
--- cfe/trunk/lib/Lex/TokenLexer.cpp (original)
+++ cfe/trunk/lib/Lex/TokenLexer.cpp Sun Apr 19 15:29:42 2009
@@ -308,13 +308,18 @@
   // Get the next token to return.
   Tok = Tokens[CurToken++];
   
+  bool TokenIsFromPaste = false;
+  
   // If this token is followed by a token paste (##) operator, paste the tokens!
   if (!isAtEnd() && Tokens[CurToken].is(tok::hashhash))
     if (PasteTokens(Tok)) {
       // When handling the microsoft /##/ extension, the final token is
       // returned by PasteTokens, not the pasted token.
       return;
+    } else {
+      TokenIsFromPaste = true;
     }
+      
 
   // The token's current location indicate where the token was lexed from.  We
   // need this information to compute the spelling of the token, but any
@@ -342,6 +347,17 @@
     // turning "for" into a keyword.
     Tok.setKind(II->getTokenID());
     
+    // If this identifier was poisoned and from a paste, emit an error.  This
+    // won't be handled by Preprocessor::HandleIdentifier because this is coming
+    // from a macro expansion.
+    if (II->isPoisoned() && TokenIsFromPaste) {
+      // We warn about __VA_ARGS__ with poisoning.
+      if (II->isStr("__VA_ARGS__"))
+        PP.Diag(Tok, diag::ext_pp_bad_vaargs_use);
+      else
+        PP.Diag(Tok, diag::err_pp_used_poisoned_id);
+    }
+    
     if (!DisableMacroExpansion && II->isHandleIdentifierCase())
       PP.HandleIdentifier(Tok);
   }
@@ -476,17 +492,6 @@
     // by saying we're skipping contents, so we need to do this manually.
     IdentifierInfo *II = PP.LookUpIdentifierInfo(Tok, ResultTokStrPtr);
     Tok.setIdentifierInfo(II);
-    
-    // If this identifier was poisoned, emit an error.  This won't be handled by
-    // Preprocessor::HandleIdentifier because this is coming from a macro
-    // expansion.
-    if (II->isPoisoned()) {
-      // We warn about __VA_ARGS__ with poisoning.
-      if (II->isStr("__VA_ARGS__"))
-        PP.Diag(Tok, diag::ext_pp_bad_vaargs_use);
-      else
-        PP.Diag(Tok, diag::err_pp_used_poisoned_id);
-    }
   }
   return false;
 }

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=69544&r1=69543&r2=69544&view=diff

==============================================================================
--- cfe/trunk/test/Preprocessor/macro_paste_bad.c (original)
+++ cfe/trunk/test/Preprocessor/macro_paste_bad.c Sun Apr 19 15:29:42 2009
@@ -18,3 +18,16 @@
 #define i   ##      // expected-error {{'##' cannot appear at start of macro expansion}}
 #define j() ##      // expected-error {{'##' cannot appear at start of macro expansion}}
 
+// Invalid token pasting.
+// PR3918
+
+// When pasting creates poisoned identifiers, we error.
+#pragma GCC poison BLARG
+BLARG  // expected-error {{attempt to use a poisoned identifier}}
+#define XX BL ## ARG
+XX     // expected-error {{attempt to use a poisoned identifier}}
+
+#define VA __VA_ ## ARGS__
+int VA;   // expected-warning {{__VA_ARGS__ can only appear in the expansion of a C99 variadic macro}}
+
+





More information about the cfe-commits mailing list