[clang] [clang][Modules] Diagnose mismatching pcm dependencies in explicit buiilds (PR #137068)

Cyndy Ishida via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 23 14:57:15 PDT 2025


================
@@ -3311,11 +3312,22 @@ ASTReader::ReadControlBlock(ModuleFile &F,
                                                    SignatureBytes.end());
         Blob = Blob.substr(ASTFileSignature::size);
 
+        // Use BaseDirectoryAsWritten to ensure we use the same path in the
+        // ModuleCache as when writing.
+        StoredFile = ReadPathBlob(BaseDirectoryAsWritten, Record, Idx, Blob);
         if (ImportedFile.empty()) {
-          // Use BaseDirectoryAsWritten to ensure we use the same path in the
-          // ModuleCache as when writing.
-          ImportedFile =
-              ReadPathBlob(BaseDirectoryAsWritten, Record, Idx, Blob);
+          ImportedFile = StoredFile;
+        } else {
+          auto ImportedFileRef =
+              PP.getFileManager().getOptionalFileRef(ImportedFile);
+          auto StoredFileRef =
+              PP.getFileManager().getOptionalFileRef(StoredFile);
+          if ((ImportedFileRef && StoredFileRef) &&
+              (*ImportedFileRef != *StoredFileRef)) {
+            Diag(diag::warn_lazy_pcm_mismatch) << ImportedFile << StoredFile;
+            Diag(diag::note_module_file_imported_by)
----------------
cyndyishida wrote:

This note could be emitted twice if the compilation eventually fails (e.g. like in the test). It would be nice to avoid that redundancy, but I didn't see an obvious way to check for that.

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


More information about the cfe-commits mailing list