Skip to content

Commit

Permalink
Exclude RedirectingFileSystem with null OverlayFileDir in VFSUsage (l…
Browse files Browse the repository at this point in the history
…lvm#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
```
  • Loading branch information
hjyamauchi authored Feb 25, 2025
1 parent 6e3b475 commit f58fde5
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions clang/lib/Lex/HeaderSearch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,17 @@ std::vector<bool> 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<llvm::vfs::RedirectingFileSystem>(&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() &&
Expand Down

0 comments on commit f58fde5

Please sign in to comment.