[clang] [llvm] [clang][ScanDeps] Allow PCHs to have different VFS overlays (PR #82294)

Jan Svoboda via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 20 08:39:01 PST 2024


================
@@ -65,11 +66,25 @@ static void optimizeHeaderSearchOpts(HeaderSearchOptions &Opts,
     llvm::DenseSet<const serialization::ModuleFile *> Visited;
     std::function<void(const serialization::ModuleFile *)> VisitMF =
         [&](const serialization::ModuleFile *MF) {
-          VFSUsage |= MF->VFSUsage;
           Visited.insert(MF);
-          for (const serialization::ModuleFile *Import : MF->Imports)
-            if (!Visited.contains(Import))
-              VisitMF(Import);
+          if (MF->Kind == serialization::MK_ImplicitModule) {
+            VFSUsage |= MF->VFSUsage;
+            // We only need to recurse into implicit modules. Other module types
+            // will have the correct set of VFSs for anything they depend on.
+            for (const serialization::ModuleFile *Import : MF->Imports)
+              if (!Visited.contains(Import))
+                VisitMF(Import);
+          } else {
+            // This is not an implicitly built module, so it may have different
+            // VFS options. Fall back to a string comparison instead.
+            auto VFSMap = PrebuiltModuleVFSMap.find(MF->FileName);
+            if (VFSMap == PrebuiltModuleVFSMap.end())
+              return;
----------------
jansvoboda11 wrote:

This almost makes it feel like it's okay to import a non-implicit module that we didn't visit when dealing with the PCH. I think it would be good to add a sanity check here by having an entry for each PCH dependency (that will map to empty set if no VFS overlay files were used) and assert here that `VFSMap != PrebuiltModuleVFSMap.end()`.

https://github.com/llvm/llvm-project/pull/82294


More information about the cfe-commits mailing list