In some cases we do not have files on disk. They are only available in the FileManager as virtual files and the SourceManager overrides their content.
Diff Detail
Event Timeline
Hi Vassil,
In which case specifically this trigger for you? I'm curious because we're sometimes hitting non-deterministic crashes in ComputeLineNumbers, wonder if it's related.
Any chance you can come up with a testcase?
We have this pattern:
FileID FID; const clang::FileEntry* FE = SM.getFileManager().getVirtualFile(source_name.str(), InputSize, 0 /* mod time*/); SM.overrideFileContents(FE, std::move(MB)); // MB is a llvm::MemoryBuffer FID = SM.createFileID(FE, NewLoc, SrcMgr::C_User); ... PP.EnterSourceFile(FID, /*DirLookup*/0, NewLoc); // PP is a clang::Preprocessor
If the memory buffer contains eg. '//expected-error: ...' when running with -verify forces the ContentCache to compute some source location information IIRC. This leads in hitting the disk, ignoring the fact that this is a virtual file with an overridden content.
I will try to come up with a test but I may need to land some interpreter infrastructure first...
We're hitting a very similar problem to this one, which I think this patch will likely fix. I can't come up with a reproducible testcase either. If you can write one better yet, but I'm ok with this as is. LGTM.
@rsmith suggested to move this one interface layer down, that is ContentCache::getBuffer. Moving it there might fix more issues. I will try to improve it and land the new version if that's not urgent for you.