diff options
author | Nico Weber <nicolasweber@gmx.de> | 2012-11-17 20:25:54 +0000 |
---|---|---|
committer | Nico Weber <nicolasweber@gmx.de> | 2012-11-17 20:25:54 +0000 |
commit | 6d926ae667cca926e77ddce1734514911706ed0a (patch) | |
tree | 2a5f1f325132192956b3b09a30aa32005bcf5dc9 /lib/Lex/Lexer.cpp | |
parent | 3f03b586351779be6947466f530f22c491b1b70f (diff) |
Fix crash on end-of-file after \ in a char literal, fixes PR14369.
This makes LexCharConstant() look more like LexStringLiteral(), which doesn't
have this bug. Add tests for eof after \ for several other cases.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@168269 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Lex/Lexer.cpp')
-rw-r--r-- | lib/Lex/Lexer.cpp | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/lib/Lex/Lexer.cpp b/lib/Lex/Lexer.cpp index 354a44db84..4698e288c0 100644 --- a/lib/Lex/Lexer.cpp +++ b/lib/Lex/Lexer.cpp @@ -1823,16 +1823,18 @@ void Lexer::LexCharConstant(Token &Result, const char *CurPtr, while (C != '\'') { // Skip escaped characters. - if (C == '\\') { - // Skip the escaped character. - getAndAdvanceChar(CurPtr, Result); - } else if (C == '\n' || C == '\r' || // Newline. - (C == 0 && CurPtr-1 == BufferEnd)) { // End of file. + if (C == '\\') + C = getAndAdvanceChar(CurPtr, Result); + + if (C == '\n' || C == '\r' || // Newline. + (C == 0 && CurPtr-1 == BufferEnd)) { // End of file. if (!isLexingRawMode() && !LangOpts.AsmPreprocessor) Diag(BufferPtr, diag::ext_unterminated_char); FormTokenWithChars(Result, CurPtr-1, tok::unknown); return; - } else if (C == 0) { + } + + if (C == 0) { if (isCodeCompletionPoint(CurPtr-1)) { PP->CodeCompleteNaturalLanguage(); FormTokenWithChars(Result, CurPtr-1, tok::unknown); |