From: Chris Lattner Date: Sun, 12 Oct 2008 04:19:49 +0000 (+0000) Subject: When in keep whitespace mode, make sure to return block comments that are X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=31f0ecae4b2d4d268d04c562a43d9fbfee96f189;p=clang When in keep whitespace mode, make sure to return block comments that are unterminated. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@57403 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Lex/Lexer.cpp b/lib/Lex/Lexer.cpp index f112aad6d3..838addedfb 100644 --- a/lib/Lex/Lexer.cpp +++ b/lib/Lex/Lexer.cpp @@ -956,7 +956,17 @@ bool Lexer::SkipBlockComment(Token &Result, const char *CurPtr) { if (C == 0 && CurPtr == BufferEnd+1) { if (!LexingRawMode) Diag(BufferPtr, diag::err_unterminated_block_comment); - BufferPtr = CurPtr-1; + --CurPtr; + + // KeepWhitespaceMode should return this broken comment as a token. Since + // it isn't a well formed comment, just return it as an 'unknown' token. + if (isKeepWhitespaceMode()) { + Result.setKind(tok::unknown); + FormTokenWithChars(Result, CurPtr); + return true; + } + + BufferPtr = CurPtr; return false; } @@ -1031,7 +1041,17 @@ bool Lexer::SkipBlockComment(Token &Result, const char *CurPtr) { // Note: the user probably forgot a */. We could continue immediately // after the /*, but this would involve lexing a lot of what really is the // comment, which surely would confuse the parser. - BufferPtr = CurPtr-1; + --CurPtr; + + // KeepWhitespaceMode should return this broken comment as a token. Since + // it isn't a well formed comment, just return it as an 'unknown' token. + if (isKeepWhitespaceMode()) { + Result.setKind(tok::unknown); + FormTokenWithChars(Result, CurPtr); + return true; + } + + BufferPtr = CurPtr; return false; } C = *CurPtr++;