diff --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp index bf8fe44e4ca9c..6fc477dff43ad 100644 --- a/clang/lib/Lex/HeaderSearch.cpp +++ b/clang/lib/Lex/HeaderSearch.cpp @@ -149,11 +149,17 @@ std::vector HeaderSearch::collectVFSUsageAndClear() const { llvm::vfs::FileSystem &RootFS = FileMgr.getVirtualFileSystem(); // TODO: This only works if the `RedirectingFileSystem`s were all created by - // `createVFSFromOverlayFiles`. + // `createVFSFromOverlayFiles`. But at least exclude the ones with null + // OverlayFileDir. RootFS.visit([&](llvm::vfs::FileSystem &FS) { if (auto *RFS = dyn_cast(&FS)) { - VFSUsage.push_back(RFS->hasBeenUsed()); - RFS->clearHasBeenUsed(); + // Skip a `RedirectingFileSystem` with null OverlayFileDir which indicates + // that they aren't created by createVFSFromOverlayFiles from the overlays + // in HeaderSearchOption::VFSOverlayFiles. + if (!RFS->getOverlayFileDir().empty()) { + VFSUsage.push_back(RFS->hasBeenUsed()); + RFS->clearHasBeenUsed(); + } } }); assert(VFSUsage.size() == getHeaderSearchOpts().VFSOverlayFiles.size() &&