diff options
author | Pawel Wodnicki <pawel@32bitmicro.com> | 2012-11-28 20:50:18 +0000 |
---|---|---|
committer | Pawel Wodnicki <pawel@32bitmicro.com> | 2012-11-28 20:50:18 +0000 |
commit | 7fade2fe3e8cb63141fac7255f7d5b99ff713dc8 (patch) | |
tree | f3b59ebd4a292daa8c7bb31588d3e61b0531b3b6 | |
parent | 7d8594fac62f4c76712c54ed59e755adf3262e7e (diff) | |
download | clang-7fade2fe3e8cb63141fac7255f7d5b99ff713dc8.tar.gz clang-7fade2fe3e8cb63141fac7255f7d5b99ff713dc8.tar.bz2 clang-7fade2fe3e8cb63141fac7255f7d5b99ff713dc8.tar.xz |
Merging r168269: into the 3.2 release branch.
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/branches/release_32@168808 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Lex/Lexer.cpp | 15 | ||||
-rw-r--r-- | test/Lexer/eof-char.c | 8 | ||||
-rw-r--r-- | test/Lexer/eof-file.c | 8 | ||||
-rw-r--r-- | test/Lexer/eof-string.c | 8 |
4 files changed, 32 insertions, 7 deletions
diff --git a/lib/Lex/Lexer.cpp b/lib/Lex/Lexer.cpp index c5fe1d879b..a5ba7dbe0a 100644 --- a/lib/Lex/Lexer.cpp +++ b/lib/Lex/Lexer.cpp @@ -1816,17 +1816,18 @@ void Lexer::LexCharConstant(Token &Result, const char *CurPtr, while (C != '\'') { // Skip escaped characters. - if (C == '\\') { - // Skip the escaped character. - // FIXME: UCN's - 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); diff --git a/test/Lexer/eof-char.c b/test/Lexer/eof-char.c new file mode 100644 index 0000000000..42ee6ea6ed --- /dev/null +++ b/test/Lexer/eof-char.c @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 %s -verify -fsyntax-only +// vim: set binary noeol: + +// This file intentionally ends without a \n on the last line. Make sure your +// editor doesn't add one. + +// expected-warning@+1{{missing terminating ' character}} expected-error@+1{{expected expression}} expected-error@+1{{expected ';'}} +char c = '\
\ No newline at end of file diff --git a/test/Lexer/eof-file.c b/test/Lexer/eof-file.c new file mode 100644 index 0000000000..43c300c04c --- /dev/null +++ b/test/Lexer/eof-file.c @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 %s -verify -fsyntax-only +// vim: set binary noeol: + +// This file intentionally ends without a \n on the last line. Make sure your +// editor doesn't add one. + +// expected-error@+1{{expected expression}} expected-error@+1{{expected ';'}} +char c = \
\ No newline at end of file diff --git a/test/Lexer/eof-string.c b/test/Lexer/eof-string.c new file mode 100644 index 0000000000..e1a60a4750 --- /dev/null +++ b/test/Lexer/eof-string.c @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 %s -verify -fsyntax-only +// vim: set binary noeol: + +// This file intentionally ends without a \n on the last line. Make sure your +// editor doesn't add one. + +// expected-warning@+1{{missing terminating '"' character}} expected-error@+1{{expected expression}} expected-error@+1{{expected ';'}} +char c = "\
\ No newline at end of file |