[clang] [clang][modules] Minor improvements to diagnosing `out of date` errors (PR #136612)

Jan Svoboda via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 22 16:01:50 PDT 2025


================
@@ -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)) ||
----------------
jansvoboda11 wrote:

> > It would be nice to reuse the FileEntry created by the ModuleManager, but it goes out of scope by the time this check happens.
> 
> Does it? It seems like it gets stored as `ModuleFile::File`.

Ah, we're talking about the case where `lookupModuleFile()` fails. But I still don't see how the file can go missing if it's already stored in the `FileManager` cache. That comment specifically talks about first calling with `/*OpenFile=*/false` and then `/*OpenFile=*/true`, which I don't think you care about.

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


More information about the cfe-commits mailing list