Skip to content

Commit f58fde5

Browse files
authored
Exclude RedirectingFileSystem with null OverlayFileDir in VFSUsage (llvm#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 ```
1 parent 6e3b475 commit f58fde5

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

clang/lib/Lex/HeaderSearch.cpp

+9-3
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,17 @@ std::vector<bool> HeaderSearch::collectVFSUsageAndClear() const {
149149

150150
llvm::vfs::FileSystem &RootFS = FileMgr.getVirtualFileSystem();
151151
// TODO: This only works if the `RedirectingFileSystem`s were all created by
152-
// `createVFSFromOverlayFiles`.
152+
// `createVFSFromOverlayFiles`. But at least exclude the ones with null
153+
// OverlayFileDir.
153154
RootFS.visit([&](llvm::vfs::FileSystem &FS) {
154155
if (auto *RFS = dyn_cast<llvm::vfs::RedirectingFileSystem>(&FS)) {
155-
VFSUsage.push_back(RFS->hasBeenUsed());
156-
RFS->clearHasBeenUsed();
156+
// Skip a `RedirectingFileSystem` with null OverlayFileDir which indicates
157+
// that they aren't created by createVFSFromOverlayFiles from the overlays
158+
// in HeaderSearchOption::VFSOverlayFiles.
159+
if (!RFS->getOverlayFileDir().empty()) {
160+
VFSUsage.push_back(RFS->hasBeenUsed());
161+
RFS->clearHasBeenUsed();
162+
}
157163
}
158164
});
159165
assert(VFSUsage.size() == getHeaderSearchOpts().VFSOverlayFiles.size() &&

0 commit comments

Comments
 (0)