Skip to content

Commit a5e9f12

Browse files
committed
Exclude RedirectingFileSystem with null OverlayFileDir in VFSUsage
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 ``` Cherrypick commit llvm#128267
1 parent 0e7ec03 commit a5e9f12

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

clang/lib/Lex/HeaderSearch.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,17 @@ std::vector<bool> HeaderSearch::collectVFSUsageAndClear() const {
150150

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

0 commit comments

Comments
 (0)