[cfe-commits] r38770 - /cfe/cfe/trunk/Lex/Preprocessor.cpp

sabre at cs.uiuc.edu sabre at cs.uiuc.edu
Wed Jul 11 09:24:28 PDT 2007


Author: sabre
Date: Wed Jul 11 11:24:28 2007
New Revision: 38770

URL: http://llvm.org/viewvc/llvm-project?rev=38770&view=rev
Log:
Poison and unpoison __VA_ARGS__ when appropriate

Modified:
    cfe/cfe/trunk/Lex/Preprocessor.cpp

Modified: cfe/cfe/trunk/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Lex/Preprocessor.cpp?rev=38770&r1=38769&r2=38770&view=diff

==============================================================================
--- cfe/cfe/trunk/Lex/Preprocessor.cpp (original)
+++ cfe/cfe/trunk/Lex/Preprocessor.cpp Wed Jul 11 11:24:28 2007
@@ -1696,8 +1696,6 @@
   LexerToken Tok;
   LexUnexpandedToken(Tok);
   
-  // FIXME: Enable __VA_ARGS__.
-
   // If this is a function-like macro definition, parse the argument list,
   // marking each of the identifiers as being used as macro arguments.  Also,
   // check other constraints on the first token of the macro body.
@@ -1732,6 +1730,15 @@
     Tok.ClearFlag(LexerToken::LeadingSpace);
   }
   
+  // If this is a definition of a variadic C99 function-like macro, not using
+  // the GNU named varargs extension, enabled __VA_ARGS__.
+  
+  // "Poison" __VA_ARGS__, which can only appear in the expansion of a macro.
+  // This gets unpoisoned where it is allowed.
+  assert(Ident__VA_ARGS__->isPoisoned() && "__VA_ARGS__ should be poisoned!");
+  if (MI->isC99Varargs())
+    Ident__VA_ARGS__->setIsPoisoned(false);
+  
   // Read the rest of the macro body.
   while (Tok.getKind() != tok::eom) {
     MI->AddTokenToBody(Tok);
@@ -1752,6 +1759,9 @@
         MI->getArgumentNum(Tok.getIdentifierInfo()) == -1) {
       Diag(Tok, diag::err_pp_stringize_not_parameter);
       delete MI;
+      
+      // Disable __VA_ARGS__ again.
+      Ident__VA_ARGS__->setIsPoisoned(true);
       return;
     }
     
@@ -1761,6 +1771,9 @@
     // Get the next token of the macro.
     LexUnexpandedToken(Tok);
   }
+  
+  // Disable __VA_ARGS__ again.
+  Ident__VA_ARGS__->setIsPoisoned(true);
 
   // Check that there is no paste (##) operator at the begining or end of the
   // replacement list.





More information about the cfe-commits mailing list