diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-12-22 04:38:07 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-12-22 04:38:07 +0000 |
commit | 04a94bcc56438b17e88db592708324041f75d48c (patch) | |
tree | b67986a2350f44cfa755c5daedd4ee0de5c7274a /lib/Lex/Lexer.cpp | |
parent | e6a24e83e71f361c7b7de82cf24ee6f5ddc7f1c2 (diff) |
In Lexer::getCharAndSizeSlow[NoWarn] if we come up against
\<newline><newline>
don't consume the second newline.
Thanks to David Blaikie for pointing out the crash!
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@147138 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Lex/Lexer.cpp')
-rw-r--r-- | lib/Lex/Lexer.cpp | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/lib/Lex/Lexer.cpp b/lib/Lex/Lexer.cpp index acb5b8a797..d3a97b42b1 100644 --- a/lib/Lex/Lexer.cpp +++ b/lib/Lex/Lexer.cpp @@ -1172,8 +1172,11 @@ Slash: Size += EscapedNewLineSize; Ptr += EscapedNewLineSize; - if (Ptr[0] == '\0') - return '\\'; + // If the char that we finally got was a \n, then we must have had + // something like \<newline><newline>. We don't want to consume the + // second newline. + if (*Ptr == '\n' || *Ptr == '\r' || *Ptr == '\0') + return ' '; // Use slow version to accumulate a correct size field. return getCharAndSizeSlow(Ptr, Size, Tok); @@ -1226,8 +1229,11 @@ Slash: Size += EscapedNewLineSize; Ptr += EscapedNewLineSize; - if (Ptr[0] == '\0') - return '\\'; + // If the char that we finally got was a \n, then we must have had + // something like \<newline><newline>. We don't want to consume the + // second newline. + if (*Ptr == '\n' || *Ptr == '\r' || *Ptr == '\0') + return ' '; // Use slow version to accumulate a correct size field. return getCharAndSizeSlowNoWarn(Ptr, Size, Features); @@ -1696,14 +1702,6 @@ bool Lexer::SkipBCPLComment(Token &Result, const char *CurPtr) { break; } - // If the char that we finally got was a \n, then we must have had something - // like \<newline><newline>. We don't want to have consumed the second - // newline, we want CurPtr, to end up pointing to it down below. - if (C == '\n' || C == '\r') { - --CurPtr; - C = 'x'; // doesn't matter what this is. - } - // If we read multiple characters, and one of those characters was a \r or // \n, then we had an escaped newline within the comment. Emit diagnostic // unless the next line is also a // comment. |