================
@@ -3349,10 +3351,29 @@ ASTReader::ReadControlBlock(ModuleFile &F,
                                       .getModuleCache()
                                       .getInMemoryModuleCache()
                                       .isPCMFinal(F.FileName);
-      if (isDiagnosedResult(Result, Capabilities) || recompilingFinalized)
+      if (isDiagnosedResult(Result, Capabilities) || recompilingFinalized) {
         Diag(diag::note_module_file_imported_by)
             << F.FileName << !F.ModuleName.empty() << F.ModuleName;
 
+        // When a Filemap is used, the ImportedFile may be different than what
+        // was encoded as a dependency in StoredFile.
+        // When this happens, look up both files when reporting that they
+        // differ. If either file does not exist, fall back to a string path
+        // check.
+        if (UseFilemap && !F.ModuleName.empty() && !StoredFile.empty()) {
+          auto ImportedFileRef =
+              PP.getFileManager().getOptionalFileRef(ImportedFile);
+          auto StoredFileRef =
+              PP.getFileManager().getOptionalFileRef(StoredFile);
+          const bool MissingFiles = !ImportedFileRef || !StoredFileRef;
+          if ((MissingFiles && (StoredFile != ImportedFile)) ||
----------------
cyndyishida wrote:

I don't think so. `StoredFile` is never checked for existence anywhere else &  
this code path can only happen if `ImportedFile` existed at the time of 
`lookupModuleFile`. 

It would be nice to reuse the FileEntry created by the ModuleManager, but it 
goes out of scope by the time this check happens. The comment in 
https://github.com/llvm/llvm-project/blob/main/clang/lib/Serialization/ModuleManager.cpp#L449
 also implies to me that it's possible the file could go _missing_ between 
those calls too. 

Somewhat related tangent: I'd like to rework a lot of this code so that when an 
`OutOfDate` case happens, the `ImportedFile` pcm is opened and we can report 
more user-facing information that represents the size check (e.g. modulemaps 
conflict), but that's out of scope right now. 

https://github.com/llvm/llvm-project/pull/136612
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to