From: Jim Grosbach Date: Thu, 15 Sep 2011 16:52:06 +0000 (+0000) Subject: Handle missing newline at EOF more gracefully in MC AsmLexer. X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=70796ca867132fd8c767301061afb9760cd69167;p=oota-llvm.git Handle missing newline at EOF more gracefully in MC AsmLexer. If we see an EOF w/o a preceding end-of-line, return an EndOfStatement token before returning the Eof token. Based on patch by Stepan Dyatkovskiy. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@139798 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/MC/MCParser/AsmLexer.cpp b/lib/MC/MCParser/AsmLexer.cpp index e446a83a58b..c76052d66e0 100644 --- a/lib/MC/MCParser/AsmLexer.cpp +++ b/lib/MC/MCParser/AsmLexer.cpp @@ -375,8 +375,15 @@ AsmToken AsmLexer::LexToken() { return AsmToken(AsmToken::EndOfStatement, StringRef(TokStart, strlen(MAI.getSeparatorString()))); } - isAtStartOfLine = false; + // If we're missing a newline at EOF, make sure we still get an + // EndOfStatement token before the Eof token. + if (CurChar == EOF && !isAtStartOfLine) { + isAtStartOfLine = true; + return AsmToken(AsmToken::EndOfStatement, StringRef(TokStart, 1)); + } + + isAtStartOfLine = false; switch (CurChar) { default: // Handle identifier: [a-zA-Z_.][a-zA-Z0-9_$.@]*