diff options
author | Chris Lattner <sabre@nondot.org> | 2009-01-16 22:39:25 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-01-16 22:39:25 +0000 |
commit | 5882771102ae4432014a95ef467f30cb030a1e3f (patch) | |
tree | b449e20ec364d5a0b60562dfd4505a05ddf2e659 /clang/lib/Lex/Lexer.cpp | |
parent | dde6eb34bb5d6193bf186ba21e280fe702f75bb2 (diff) | |
download | bcm5719-llvm-5882771102ae4432014a95ef467f30cb030a1e3f.tar.gz bcm5719-llvm-5882771102ae4432014a95ef467f30cb030a1e3f.zip |
Fix PR2477 - clang misparses "//*" in C89 mode
llvm-svn: 62368
Diffstat (limited to 'clang/lib/Lex/Lexer.cpp')
-rw-r--r-- | clang/lib/Lex/Lexer.cpp | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp index 0eb439a27b6..fa29d0a38e0 100644 --- a/clang/lib/Lex/Lexer.cpp +++ b/clang/lib/Lex/Lexer.cpp @@ -1300,7 +1300,8 @@ LexNextToken: // If the next token is obviously a // or /* */ comment, skip it efficiently // too (without going through the big switch stmt). - if (CurPtr[0] == '/' && CurPtr[1] == '/' && !inKeepCommentMode()) { + if (CurPtr[0] == '/' && CurPtr[1] == '/' && !inKeepCommentMode() && + Features.BCPLComment) { SkipBCPLComment(Result, CurPtr+2); goto SkipIgnoredUnits; } else if (CurPtr[0] == '/' && CurPtr[1] == '*' && !inKeepCommentMode()) { @@ -1480,18 +1481,32 @@ LexNextToken: // 6.4.9: Comments Char = getCharAndSize(CurPtr, SizeTmp); if (Char == '/') { // BCPL comment. - if (SkipBCPLComment(Result, ConsumeChar(CurPtr, SizeTmp, Result))) - return; // KeepCommentMode + // Even if BCPL comments are disabled (e.g. in C89 mode), we generally + // want to lex this as a comment. There is one problem with this though, + // that in one particular corner case, this can change the behavior of the + // resultant program. For example, In "foo //**/ bar", C89 would lex + // this as "foo / bar" and langauges with BCPL comments would lex it as + // "foo". Check to see if the character after the second slash is a '*'. + // If so, we will lex that as a "/" instead of the start of a comment. + if (Features.BCPLComment || + getCharAndSize(CurPtr+SizeTmp, SizeTmp2) != '*') { + if (SkipBCPLComment(Result, ConsumeChar(CurPtr, SizeTmp, Result))) + return; // KeepCommentMode - // It is common for the tokens immediately after a // comment to be - // whitespace (indentation for the next line). Instead of going through - // the big switch, handle it efficiently now. - goto SkipIgnoredUnits; - } else if (Char == '*') { // /**/ comment. + // It is common for the tokens immediately after a // comment to be + // whitespace (indentation for the next line). Instead of going through + // the big switch, handle it efficiently now. + goto SkipIgnoredUnits; + } + } + + if (Char == '*') { // /**/ comment. if (SkipBlockComment(Result, ConsumeChar(CurPtr, SizeTmp, Result))) return; // KeepCommentMode goto LexNextToken; // GCC isn't tail call eliminating. - } else if (Char == '=') { + } + + if (Char == '=') { CurPtr = ConsumeChar(CurPtr, SizeTmp, Result); Kind = tok::slashequal; } else { |