[cfe-commits] r95253 - /cfe/trunk/lib/Lex/Lexer.cpp

Chris Lattner sabre at nondot.org
Wed Feb 3 13:06:22 PST 2010


Author: lattner
Date: Wed Feb  3 15:06:21 2010
New Revision: 95253

URL: http://llvm.org/viewvc/llvm-project?rev=95253&view=rev
Log:
don't inform comment handlers about comments in #if 0 blocks,
doing so invalidates the file guard optimization and is not
in the spirit of "#if 0" because it is supposed to completely
skip everything, even if it isn't lexically valid. Patch by
Abramo Bagnara!

Modified:
    cfe/trunk/lib/Lex/Lexer.cpp

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

==============================================================================
--- cfe/trunk/lib/Lex/Lexer.cpp (original)
+++ cfe/trunk/lib/Lex/Lexer.cpp Wed Feb  3 15:06:21 2010
@@ -985,10 +985,11 @@
     if (CurPtr == BufferEnd+1) { --CurPtr; break; }
   } while (C != '\n' && C != '\r');
 
-  // Found but did not consume the newline.
-  if (PP && PP->HandleComment(Result,
-                              SourceRange(getSourceLocation(BufferPtr),
-                                          getSourceLocation(CurPtr)))) {
+  // Found but did not consume the newline.  Notify comment handlers about the
+  // comment unless we're in a #if 0 block.
+  if (PP && !isLexingRawMode() &&
+      PP->HandleComment(Result, SourceRange(getSourceLocation(BufferPtr),
+                                            getSourceLocation(CurPtr)))) {
     BufferPtr = CurPtr;
     return true; // A token has to be returned.
   }
@@ -1235,9 +1236,10 @@
     C = *CurPtr++;
   }
 
-  if (PP && PP->HandleComment(Result,
-                              SourceRange(getSourceLocation(BufferPtr),
-                                          getSourceLocation(CurPtr)))) {
+  // Notify comment handlers about the comment unless we're in a #if 0 block.
+  if (PP && !isLexingRawMode() &&
+      PP->HandleComment(Result, SourceRange(getSourceLocation(BufferPtr),
+                                            getSourceLocation(CurPtr)))) {
     BufferPtr = CurPtr;
     return true; // A token has to be returned.
   }





More information about the cfe-commits mailing list