[Syntax] Fix a crash when dumping empty token buffer
llvm-svn: 363801
This commit is contained in:
parent
102b1efd53
commit
26c066d66d
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue