[Syntax] Fix a crash when dumping empty token buffer

llvm-svn: 363801
This commit is contained in:
Ilya Biryukov 2019-06-19 13:56:36 +00:00
parent 102b1efd53
commit 26c066d66d
2 changed files with 11 additions and 3 deletions

View File

@ -477,8 +477,7 @@ std::string TokenBuffer::dumpForTests() const {
auto DumpTokens = [this, &PrintToken](llvm::raw_ostream &OS,
llvm::ArrayRef<syntax::Token> Tokens) {
if (Tokens.size() == 1) {
assert(Tokens[0].kind() == tok::eof);
if (Tokens.empty()) {
OS << "<empty>";
return;
}
@ -495,7 +494,8 @@ std::string TokenBuffer::dumpForTests() const {
OS << "expanded tokens:\n"
<< " ";
DumpTokens(OS, ExpandedTokens);
// (!) we do not show '<eof>'.
DumpTokens(OS, llvm::makeArrayRef(ExpandedTokens).drop_back());
OS << "\n";
std::vector<FileID> Keys;

View File

@ -290,6 +290,14 @@ file './input.cpp'
# pragma GCC visibility push ( public ) # pragma GCC visibility pop
mappings:
['#'_0, '<eof>'_13) => ['<eof>'_0, '<eof>'_0)
)"},
// Empty files should not crash.
{R"cpp()cpp", R"(expanded tokens:
<empty>
file './input.cpp'
spelled tokens:
<empty>
no mappings.
)"}};
for (auto &Test : TestCases)
EXPECT_EQ(collectAndDump(Test.first), Test.second)