]> granicus.if.org Git - clang/commitdiff
Fix PR1820, an incredibly subtle macro expansion bug that Neil discovered.
authorChris Lattner <sabre@nondot.org>
Fri, 23 Nov 2007 06:50:21 +0000 (06:50 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 23 Nov 2007 06:50:21 +0000 (06:50 +0000)
Neil, please review this fix.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44285 91177308-0d34-0410-b5e6-96231b3b80d8

Lex/Preprocessor.cpp
test/Preprocessor/macro_disable4.c [new file with mode: 0644]

index 0970590afe9d44b65f790277b4edf6890e3dd84f..a685b0b27b8cc15abd29696022a4b62cb72150d0 100644 (file)
@@ -941,6 +941,16 @@ MacroArgs *Preprocessor::ReadFunctionLikeMacroArgs(Token &MacroName,
         // 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);
diff --git a/test/Preprocessor/macro_disable4.c b/test/Preprocessor/macro_disable4.c
new file mode 100644 (file)
index 0000000..4858813
--- /dev/null
@@ -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));