[PATCH] D91300: WIP: Frontend: Use an InMemoryFileSystem for the RemappedFiles parameter in ASTUnit

Duncan P. N. Exon Smith via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 11 13:50:47 PST 2020


dexonsmith created this revision.
dexonsmith added reviewers: arphaman, JDevlieghere, jansvoboda11, akyrtzi.
Herald added a subscriber: ributzka.
dexonsmith requested review of this revision.

Re-implement the `RemappedFiles` parameter to various `ASTUnit` entry points by storing buffers in an `InMemoryFileSystem`. This parameter is commonly used by indexing tools to pass in source files that haven't been saved to disk (yet). This is the same strategy `ClangTool` switched to in 2015.

The previous implementation added them to `PreprocessorOptions::RemappedFileBuffers`, which eventually triggers calls to `FileManager::getVirtualFile` and `SourceManager::overrideFileContents`. That's one of the blockers for sinking the content cache from `SourceManager` down to `FileManager`. The new strategy is also a bit cleaner (the old one predates `llvm::vfs::FileSystem`).

Follow-ups will handle the other two uses of `RemappedFileBuffers` in `ASTUnit`. One is for the preamble's serialized AST. The other is for overriding the main file buffer, which is a bit tricky since we need the `ASTWriter` to save the preamble-only version.

WIP: I'm not totally happy with this patch yet, but tests are finally passing so I'm posting this for early review. In the meantime I'll continue peeling off what I can for prep patches (or there may be changes I can just delete). Among other things, I want to add a test (in a prep patch) for the handling of a file showing up twice in the same `RemappedFiles` vector, since it was pretty tough to discover I needed special logic for that.


https://reviews.llvm.org/D91300

Files:
  clang/include/clang/Frontend/ASTUnit.h
  clang/include/clang/Frontend/PrecompiledPreamble.h
  clang/lib/Frontend/ASTUnit.cpp
  clang/lib/Frontend/PrecompiledPreamble.cpp
  clang/tools/libclang/CIndex.cpp
  clang/tools/libclang/CIndexCodeCompletion.cpp
  clang/unittests/Frontend/PCHPreambleTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91300.304643.patch
Type: text/x-patch
Size: 34766 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201111/c203daa1/attachment-0001.bin>


More information about the cfe-commits mailing list