From f58fde585775a7c25dc673076db914f8d1866081 Mon Sep 17 00:00:00 2001 From: Hiroshi Yamauchi <56735936+hjyamauchi@users.noreply.github.com> Date: Mon, 24 Feb 2025 22:52:15 -0800 Subject: [PATCH] Exclude RedirectingFileSystem with null OverlayFileDir in VFSUsage (#128267) This is to avoid assertion failures like the following when RedirectingFileSystem's are created and used outside createVFSFromOverlayFiles. ``` Assertion failed: VFSUsage.size() == getHeaderSearchOpts().VFSOverlayFiles.size() && "A different number of RedirectingFileSystem's were present than " "-ivfsoverlay options passed to Clang!", file S:\SourceCache\llvm-project\clang\lib\Lex\HeaderSearch.cpp, line 162 ``` --- clang/lib/Lex/HeaderSearch.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) 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() &&