Author: Hiroshi Yamauchi
Date: 2025-02-24T22:52:15-08:00
New Revision: f58fde585775a7c25dc673076db914f8d1866081

URL: 
https://github.com/llvm/llvm-project/commit/f58fde585775a7c25dc673076db914f8d1866081
DIFF: 
https://github.com/llvm/llvm-project/commit/f58fde585775a7c25dc673076db914f8d1866081.diff

LOG: 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
```

Added: 
    

Modified: 
    clang/lib/Lex/HeaderSearch.cpp

Removed: 
    


################################################################################
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<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() &&


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to