diff options
| author | Chris Lattner <sabre@nondot.org> | 2007-07-21 23:43:37 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2007-07-21 23:43:37 +0000 |
| commit | c850ad6ee122d3757d9dc1a67d4ddc9e9b219a42 (patch) | |
| tree | e82298e70245442c508a0d8a1641c85f2bdb1c06 | |
| parent | 7649abce462d3613fc075e662e0ba9ef78a7eb4b (diff) | |
| download | bcm5719-llvm-c850ad6ee122d3757d9dc1a67d4ddc9e9b219a42.tar.gz bcm5719-llvm-c850ad6ee122d3757d9dc1a67d4ddc9e9b219a42.zip | |
Fix a lexer bug where we incorrectly rejected
int i = /*/ */ 1;
Thanks to Neil for pointing this out.
llvm-svn: 40379
| -rw-r--r-- | clang/Lex/Lexer.cpp | 13 | ||||
| -rw-r--r-- | clang/test/Lexer/block_cmt_end.c | 3 |
2 files changed, 15 insertions, 1 deletions
diff --git a/clang/Lex/Lexer.cpp b/clang/Lex/Lexer.cpp index 1518d8895ce..e92fc94da2e 100644 --- a/clang/Lex/Lexer.cpp +++ b/clang/Lex/Lexer.cpp @@ -817,13 +817,24 @@ bool Lexer::SkipBlockComment(Token &Result, const char *CurPtr) { // we find it, check to see if it was preceeded by a *. This common // optimization helps people who like to put a lot of * characters in their // comments. - unsigned char C = *CurPtr++; + + // The first character we get with newlines and trigraphs skipped to handle + // the degenerate /*/ case below correctly if the * has an escaped newline + // after it. + unsigned CharSize; + unsigned char C = getCharAndSize(CurPtr, CharSize); + CurPtr += CharSize; if (C == 0 && CurPtr == BufferEnd+1) { Diag(BufferPtr, diag::err_unterminated_block_comment); BufferPtr = CurPtr-1; return true; } + // Check to see if the first character after the '/*' is another /. If so, + // then this slash does not end the block comment, it is part of it. + if (C == '/') + C = *CurPtr++; + while (1) { // Skip over all non-interesting characters until we find end of buffer or a // (probably ending) '/' character. diff --git a/clang/test/Lexer/block_cmt_end.c b/clang/test/Lexer/block_cmt_end.c index b111b2a23e3..20d90452213 100644 --- a/clang/test/Lexer/block_cmt_end.c +++ b/clang/test/Lexer/block_cmt_end.c @@ -6,6 +6,9 @@ RUN: clang -parse-ast-check %s */ +// This is a simple comment, /*/ does not end a comment, the trailing */ does. +int i = /*/ */ 1; + /* abc next comment ends with normal escaped newline: |

