Commit fde85543 authored by Pawel Wodnicki's avatar Pawel Wodnicki
Browse files

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.

llvm-svn: 168808
parent feca2ad3
Loading
Loading
Loading
Loading
+8 −7
Original line number Diff line number Diff line
@@ -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.
    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);
+8 −0
Original line number Diff line number Diff line
// 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
+8 −0
Original line number Diff line number Diff line
// 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
+8 −0
Original line number Diff line number Diff line
// 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