mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 12:31:04 +01:00
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:
co-authored by
Richard Smith
parent
2c45cb3be8
commit
a93e621488
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user