[flang-commits] [flang] [flang] Use module file hashes for more checking and disambiguation (PR #80354)

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Fri Feb 2 08:45:59 PST 2024


================
@@ -1250,6 +1333,47 @@ Scope *ModFileReader::Read(const SourceName &name,
       options.searchDirectories.push_back(dir);
     }
   }
+
+  // Look for the right module file if its hash is known
+  auto requiredHash{
+      context_.moduleDependences().GetRequiredHash(name.ToString())};
+  if (requiredHash && !fatalError) {
+    std::vector<std::string> misses;
+    for (const std::string &maybe :
+        parser::LocateSourceFileAll(path, options.searchDirectories)) {
+      if (const auto *srcFile{context_.allCookedSources().allSources().Open(
+              maybe, llvm::errs())}) {
+        if (auto checkSum{VerifyHeader(srcFile->content())}) {
+          if (*checkSum == *requiredHash) {
+            path = maybe;
+            if (!misses.empty()) {
+              auto &msg{context_.Say(name,
+                  "Module file for '%s' appears later in the module search path than conflicting modules with different checksums"_warn_en_US,
+                  name.ToString())};
+              for (const std::string &m : misses) {
+                msg.Attach(
+                    name, "Module file with a conflicting name: '%s'"_en_US, m);
+              }
+            }
+            misses.clear();
+            break;
+          } else {
+            misses.emplace_back(maybe);
+          }
+        }
+      }
+    }
+    if (!misses.empty()) {
+      auto &msg{Say(name, ancestorName,
+          "Could not find a module file for '%s' in the module search path with the expected checksum"_err_en_US,
----------------
klausler wrote:

The provenance printed for the message contains the name of the module.

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


More information about the flang-commits mailing list