diff options
author | Chris Lattner <sabre@nondot.org> | 2010-07-07 23:24:27 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2010-07-07 23:24:27 +0000 |
commit | d80f786689d608e5c22d6e1045884de7aff76c40 (patch) | |
tree | 82b6b8a5049dcde5273bbdcb1466a6528ff73b8c /lib/Lex/Lexer.cpp | |
parent | c0fee50ce432a63b7c4ee73e73a464af1bf388a0 (diff) |
fix PR4499, patch by Kyle Dean!
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@107836 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Lex/Lexer.cpp')
-rw-r--r-- | lib/Lex/Lexer.cpp | 40 |
1 files changed, 16 insertions, 24 deletions
diff --git a/lib/Lex/Lexer.cpp b/lib/Lex/Lexer.cpp index 84457fa2c8..91b14f638d 100644 --- a/lib/Lex/Lexer.cpp +++ b/lib/Lex/Lexer.cpp @@ -820,41 +820,33 @@ void Lexer::LexAngledStringLiteral(Token &Result, const char *CurPtr) { void Lexer::LexCharConstant(Token &Result, const char *CurPtr) { const char *NulCharacter = 0; // Does this character contain the \0 character? - // Handle the common case of 'x' and '\y' efficiently. char C = getAndAdvanceChar(CurPtr, Result); if (C == '\'') { if (!isLexingRawMode() && !Features.AsmPreprocessor) Diag(BufferPtr, diag::err_empty_character); FormTokenWithChars(Result, CurPtr, tok::unknown); return; - } else if (C == '\\') { - // Skip the escaped character. - // FIXME: UCN's. - C = getAndAdvanceChar(CurPtr, Result); } - if (C && C != '\n' && C != '\r' && CurPtr[0] == '\'') { - ++CurPtr; - } else { - // Fall back on generic code for embedded nulls, newlines, wide chars. - do { - // Skip escaped characters. - if (C == '\\') { - // Skip the escaped character. - C = getAndAdvanceChar(CurPtr, Result); - } else if (C == '\n' || C == '\r' || // Newline. - (C == 0 && CurPtr-1 == BufferEnd)) { // End of file. - if (!isLexingRawMode() && !Features.AsmPreprocessor) - Diag(BufferPtr, diag::err_unterminated_char); - FormTokenWithChars(Result, CurPtr-1, tok::unknown); - return; - } else if (C == 0) { - NulCharacter = CurPtr-1; - } + while (C != '\'') { + // Skip escaped characters. + if (C == '\\') { + // Skip the escaped character. + // FIXME: UCN's C = getAndAdvanceChar(CurPtr, Result); - } while (C != '\''); + } else if (C == '\n' || C == '\r' || // Newline. + (C == 0 && CurPtr-1 == BufferEnd)) { // End of file. + if (!isLexingRawMode() && !Features.AsmPreprocessor) + Diag(BufferPtr, diag::err_unterminated_char); + FormTokenWithChars(Result, CurPtr-1, tok::unknown); + return; + } else if (C == 0) { + NulCharacter = CurPtr-1; + } + C = getAndAdvanceChar(CurPtr, Result); } + // If a nul character existed in the character, warn about it. if (NulCharacter && !isLexingRawMode()) Diag(NulCharacter, diag::null_in_char); |