[cfe-commits] r40026 - in /cfe/trunk: Lex/Preprocessor.cpp test/Preprocessor/function_macro_file.c test/Preprocessor/function_macro_file.h

Chris Lattner sabre at nondot.org
Wed Jul 18 17:07:37 PDT 2007


Author: lattner
Date: Wed Jul 18 19:07:36 2007
New Revision: 40026

URL: http://llvm.org/viewvc/llvm-project?rev=40026&view=rev
Log:
Correctly respect C99 5.1.1.2p4 when searching for the first '(' of
a function-like macro invocation.  Patch contributed by Neil Booth.

Added:
    cfe/trunk/test/Preprocessor/function_macro_file.c
    cfe/trunk/test/Preprocessor/function_macro_file.h
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=40026&r1=40025&r2=40026&view=diff

==============================================================================
--- cfe/trunk/Lex/Preprocessor.cpp (original)
+++ cfe/trunk/Lex/Preprocessor.cpp Wed Jul 18 19:07:36 2007
@@ -554,14 +554,24 @@
     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;
     }
   }
 

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

==============================================================================
--- cfe/trunk/test/Preprocessor/function_macro_file.c (added)
+++ cfe/trunk/test/Preprocessor/function_macro_file.c Wed Jul 18 19:07:36 2007
@@ -0,0 +1,5 @@
+/* RUN: clang -E -P %s | grep f
+ */
+
+#include "function_macro_file.h"
+()

Added: cfe/trunk/test/Preprocessor/function_macro_file.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/function_macro_file.h?rev=40026&view=auto

==============================================================================
--- cfe/trunk/test/Preprocessor/function_macro_file.h (added)
+++ cfe/trunk/test/Preprocessor/function_macro_file.h Wed Jul 18 19:07:36 2007
@@ -0,0 +1,3 @@
+
+#define f() x
+f





More information about the cfe-commits mailing list