Add vfs support to toolchain. (#2888)

This adds vfs support to the toolchain, allowing Driver to take in-memory inputs in tests. As a consequence, I'm simplifying SourceBuffer: rather than allowing tests to pass in their own memory buffer, I'm using InMemoryFileSystem to push for greater consistency with production code. This does hit a quirk where I need to be careful about null terminator handling because fuzzer imports don't always have one, but that's probably more robust anyways.

Co-authored-by: Richard Smith <richard@metafoo.co.uk>
This commit is contained in:
Jon Ross-Perkins
2023-06-12 13:19:57 -07:00
committed by GitHub
co-authored by Richard Smith
parent 2c45cb3be8
commit a93e621488
17 changed files with 217 additions and 367 deletions
+8 -3
View File
@@ -22,9 +22,14 @@ extern "C" int LLVMFuzzerTestOneInput(const unsigned char* data,
if (size > 100000) {
return 0;
}
auto source = SourceBuffer::CreateFromText(
llvm::StringRef(reinterpret_cast<const char*>(data), size));
static constexpr llvm::StringLiteral TestFileName = "test.carbon";
llvm::vfs::InMemoryFileSystem fs;
llvm::StringRef data_ref(reinterpret_cast<const char*>(data), size);
CARBON_CHECK(fs.addFile(
TestFileName, /*ModificationTime=*/0,
llvm::MemoryBuffer::getMemBuffer(data_ref, /*BufferName=*/TestFileName,
/*RequiresNullTerminator=*/false)));
auto source = SourceBuffer::CreateFromFile(fs, TestFileName);
// Lex the input.
auto tokens = TokenizedBuffer::Lex(*source, NullDiagnosticConsumer());