[cfe-commits] r168269 - in /cfe/trunk: lib/Lex/Lexer.cpp test/Lexer/eof-char.c test/Lexer/eof-file.c test/Lexer/eof-string.c

Nico Weber thakis at chromium.org
Sat Nov 17 12:42:00 PST 2012


Doug, Pawel marked PR14369 as blocker for the 3.2 release. Is it ok to
merge this? (And if so, how do I do that?)

On Sat, Nov 17, 2012 at 12:25 PM, Nico Weber <nicolasweber at gmx.de> wrote:
> Author: nico
> Date: Sat Nov 17 14:25:54 2012
> New Revision: 168269
>
> URL: http://llvm.org/viewvc/llvm-project?rev=168269&view=rev
> Log:
> 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.
>
>
> Added:
>     cfe/trunk/test/Lexer/eof-char.c
>     cfe/trunk/test/Lexer/eof-file.c
>     cfe/trunk/test/Lexer/eof-string.c
> Modified:
>     cfe/trunk/lib/Lex/Lexer.cpp
>
> Modified: cfe/trunk/lib/Lex/Lexer.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Lexer.cpp?rev=168269&r1=168268&r2=168269&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Lex/Lexer.cpp (original)
> +++ cfe/trunk/lib/Lex/Lexer.cpp Sat Nov 17 14:25:54 2012
> @@ -1823,16 +1823,18 @@
>
>    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);
>
> Added: cfe/trunk/test/Lexer/eof-char.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Lexer/eof-char.c?rev=168269&view=auto
> ==============================================================================
> --- cfe/trunk/test/Lexer/eof-char.c (added)
> +++ cfe/trunk/test/Lexer/eof-char.c Sat Nov 17 14:25:54 2012
> @@ -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 at +1{{missing terminating ' character}} expected-error at +1{{expected expression}} expected-error at +1{{expected ';'}}
> +char c = '\
> \ No newline at end of file
>
> Added: cfe/trunk/test/Lexer/eof-file.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Lexer/eof-file.c?rev=168269&view=auto
> ==============================================================================
> --- cfe/trunk/test/Lexer/eof-file.c (added)
> +++ cfe/trunk/test/Lexer/eof-file.c Sat Nov 17 14:25:54 2012
> @@ -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 at +1{{expected expression}} expected-error at +1{{expected ';'}}
> +char c = \
> \ No newline at end of file
>
> Added: cfe/trunk/test/Lexer/eof-string.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Lexer/eof-string.c?rev=168269&view=auto
> ==============================================================================
> --- cfe/trunk/test/Lexer/eof-string.c (added)
> +++ cfe/trunk/test/Lexer/eof-string.c Sat Nov 17 14:25:54 2012
> @@ -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 at +1{{missing terminating '"' character}} expected-error at +1{{expected expression}} expected-error at +1{{expected ';'}}
> +char c = "\
> \ No newline at end of file
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits



More information about the cfe-commits mailing list