[cfe-commits] r44285 - in /cfe/trunk: Lex/Preprocessor.cpp test/Preprocessor/macro_disable4.c

Chris Lattner sabre at nondot.org
Thu Nov 22 22:50:23 PST 2007


Author: lattner
Date: Fri Nov 23 00:50:21 2007
New Revision: 44285

URL: http://llvm.org/viewvc/llvm-project?rev=44285&view=rev
Log:
Fix PR1820, an incredibly subtle macro expansion bug that Neil discovered.

Neil, please review this fix.

Added:
    cfe/trunk/test/Preprocessor/macro_disable4.c
Modified:
    cfe/trunk/Lex/Preprocessor.cpp

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

==============================================================================
--- cfe/trunk/Lex/Preprocessor.cpp (original)
+++ cfe/trunk/Lex/Preprocessor.cpp Fri Nov 23 00:50:21 2007
@@ -941,6 +941,16 @@
         // If this is a comment token in the argument list and we're just in
         // -C mode (not -CC mode), discard the comment.
         continue;
+      } else if (Tok.is(tok::identifier)) {
+        // Reading macro arguments can cause macros that we are currently
+        // expanding from to be popped off the expansion stack.  Doing so causes
+        // them to be reenabled for expansion.  Here we record whether any
+        // identifiers we lex as macro arguments correspond to disabled macros.
+        // If so, we mark the token as noexpand.  This is a subtle aspect of 
+        // C99 6.10.3.4p2.
+        if (MacroInfo *MI = getMacroInfo(Tok.getIdentifierInfo()))
+          if (!MI->isEnabled())
+            Tok.setFlag(Token::DisableExpand);
       }
   
       ArgTokens.push_back(Tok);

Added: cfe/trunk/test/Preprocessor/macro_disable4.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/macro_disable4.c?rev=44285&view=auto

==============================================================================
--- cfe/trunk/test/Preprocessor/macro_disable4.c (added)
+++ cfe/trunk/test/Preprocessor/macro_disable4.c Fri Nov 23 00:50:21 2007
@@ -0,0 +1,6 @@
+// RUN: clang -P -E %s | grep 'int f(void)'
+// PR1820
+
+#define f(x) h(x
+#define h(x) x(void) 
+extern int f(f));





More information about the cfe-commits mailing list