There is an explicit option for the lexer to support this, but we crash
when `-preserve-comments` is enabled because it checks for
`getTok().getString().empty()` to detect the case. This doesn't
work currently because the lexer reports this case as a string of length
1, containing a null byte.
Change the lexer to instead report this case via an empty string, as the
null terminator isn't logically a part of the textual input, and the
check for `.empty()` seems natural and obvious in the calling code.
Reviewed By: niravd
Differential Revision: https://reviews.llvm.org/D92681
if (CurChar == EOF && !IsAtStartOfStatement && EndStatementAtEOF) {
IsAtStartOfLine = true;
IsAtStartOfStatement = true;
- return AsmToken(AsmToken::EndOfStatement, StringRef(TokStart, 1));
+ return AsmToken(AsmToken::EndOfStatement, StringRef(TokStart, 0));
}
IsAtStartOfLine = false;
bool OldIsAtStartOfStatement = IsAtStartOfStatement;
--- /dev/null
+.text
\ No newline at end of file
#RUN: llvm-mc -preserve-comments -n -triple i386-linux-gnu < %s > %t
#RUN: diff -b %s %t
+ #RUN: llvm-mc -preserve-comments -n -triple i386-linux-gnu < %p/Inputs/no-newline-at-end-of-file.s | FileCheck %s
.text
foo: #Comment here
#endif
.ident "clang version 3.9.0"
.section ".note.GNU-stack","",@progbits
+
+ #Confirm we don't crash on inputs without a terminating newline.
+ #CHECK: .text