From: Chris Lattner Date: Wed, 3 Feb 2010 21:06:21 +0000 (+0000) Subject: don't inform comment handlers about comments in #if 0 blocks, X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3d0ad58b28e0d50fca7f21c6a078b05370510288;p=clang 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! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@95253 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Lex/Lexer.cpp b/lib/Lex/Lexer.cpp index afd1ba8851..3207062cca 100644 --- a/lib/Lex/Lexer.cpp +++ b/lib/Lex/Lexer.cpp @@ -985,10 +985,11 @@ bool Lexer::SkipBCPLComment(Token &Result, const char *CurPtr) { 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 @@ bool Lexer::SkipBlockComment(Token &Result, const char *CurPtr) { 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. }