]> granicus.if.org Git - clang/commitdiff
Correctly respect C99 5.1.1.2p4 when searching for the first '(' of
authorChris Lattner <sabre@nondot.org>
Thu, 19 Jul 2007 00:07:36 +0000 (00:07 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 19 Jul 2007 00:07:36 +0000 (00:07 +0000)
a function-like macro invocation.  Patch contributed by Neil Booth.

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

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

index 93017937d532cde6aabb7454e5ab05a79e578c4a..bc7ad12e5647ea67ee80fd33ac2e086d73fee59f 100644 (file)
@@ -554,14 +554,24 @@ bool Preprocessor::isNextPPTokenLParen() {
     Val = CurMacroExpander->isNextTokenLParen();
   
   if (Val == 2) {
-    // If we ran off the end of the lexer or macro expander, walk the include
-    // stack, looking for whatever will return the next token.
-    for (unsigned i = IncludeMacroStack.size(); Val == 2 && i != 0; --i) {
+    // We have run off the end.  If it's a source file we don't
+    // examine enclosing ones (C99 5.1.1.2p4).  Otherwise walk up the
+    // macro stack.
+    if (CurLexer)
+      return false;
+    for (unsigned i = IncludeMacroStack.size(); i != 0; --i) {
       IncludeStackInfo &Entry = IncludeMacroStack[i-1];
       if (Entry.TheLexer)
         Val = Entry.TheLexer->isNextPPTokenLParen();
       else
         Val = Entry.TheMacroExpander->isNextTokenLParen();
+      
+      if (Val != 2)
+        break;
+      
+      // Ran off the end of a source file?
+      if (Entry.TheLexer)
+        return false;
     }
   }
 
diff --git a/test/Preprocessor/function_macro_file.c b/test/Preprocessor/function_macro_file.c
new file mode 100644 (file)
index 0000000..eeb9256
--- /dev/null
@@ -0,0 +1,5 @@
+/* RUN: clang -E -P %s | grep f
+ */
+
+#include "function_macro_file.h"
+()
diff --git a/test/Preprocessor/function_macro_file.h b/test/Preprocessor/function_macro_file.h
new file mode 100644 (file)
index 0000000..43d1199
--- /dev/null
@@ -0,0 +1,3 @@
+
+#define f() x
+f