[cfe-commits] r51843 - in /cfe/trunk: lib/Lex/PPDirectives.cpp test/Lexer/multiple-include.c

Nuno Lopes nunoplopes at sapo.pt
Sun Jun 1 11:31:24 PDT 2008


Author: nlopes
Date: Sun Jun  1 13:31:24 2008
New Revision: 51843

URL: http://llvm.org/viewvc/llvm-project?rev=51843&view=rev
Log:
fix PR2357 (#ifs didnt invalidate the multiple-inclusion optimization state)

Added:
    cfe/trunk/test/Lexer/multiple-include.c
Modified:
    cfe/trunk/lib/Lex/PPDirectives.cpp

Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=51843&r1=51842&r2=51843&view=diff

==============================================================================
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Sun Jun  1 13:31:24 2008
@@ -1059,17 +1059,18 @@
   IdentifierInfo *IfNDefMacro = 0;
   bool ConditionalTrue = EvaluateDirectiveExpression(IfNDefMacro);
   
+
+  // If this condition is equivalent to #ifndef X, and if this is the first
+  // directive seen, handle it for the multiple-include optimization.
+  if (CurLexer->getConditionalStackDepth() == 0) {
+    if (!ReadAnyTokensBeforeDirective && IfNDefMacro)
+      CurLexer->MIOpt.EnterTopLevelIFNDEF(IfNDefMacro);
+    else
+      CurLexer->MIOpt.EnterTopLevelConditional();
+  }
+
   // Should we include the stuff contained by this directive?
   if (ConditionalTrue) {
-    // If this condition is equivalent to #ifndef X, and if this is the first
-    // directive seen, handle it for the multiple-include optimization.
-    if (CurLexer->getConditionalStackDepth() == 0) {
-      if (!ReadAnyTokensBeforeDirective && IfNDefMacro)
-        CurLexer->MIOpt.EnterTopLevelIFNDEF(IfNDefMacro);
-      else
-        CurLexer->MIOpt.EnterTopLevelConditional();
-    }
-    
     // Yes, remember that we are inside a conditional, then lex the next token.
     CurLexer->pushConditionalLevel(IfToken.getLocation(), /*wasskip*/false,
                                    /*foundnonskip*/true, /*foundelse*/false);

Added: cfe/trunk/test/Lexer/multiple-include.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Lexer/multiple-include.c?rev=51843&view=auto

==============================================================================
--- cfe/trunk/test/Lexer/multiple-include.c (added)
+++ cfe/trunk/test/Lexer/multiple-include.c Sun Jun  1 13:31:24 2008
@@ -0,0 +1,27 @@
+// RUN: clang %s -fsyntax-only
+
+#ifndef XVID_AUTO_INCLUDE
+
+#define XVID_AUTO_INCLUDE
+#define FUNC_H      H_Pass_16_C
+#include "multiple-include.c"
+
+#define FUNC_H      H_Pass_8_C
+
+#include "multiple-include.c"
+#undef XVID_AUTO_INCLUDE
+
+typedef void ff();
+typedef struct { ff *a;} S;
+
+S s = { H_Pass_8_C };
+
+#endif 
+
+#if defined(XVID_AUTO_INCLUDE) && defined(REFERENCE_CODE)
+#elif defined(XVID_AUTO_INCLUDE) && !defined(REFERENCE_CODE)
+
+static void FUNC_H(){};
+#undef FUNC_H
+
+#endif





More information about the cfe-commits mailing list