[flang-commits] [flang] [flang] Use module file hashes for more checking and disambiguation (PR #80354)
via flang-commits
flang-commits at lists.llvm.org
Fri Feb 2 07:23:56 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,
----------------
jeanPerier wrote:
It could be nice hinting to the user that some module may be outdated (and point to it, although maybe we do not know here which module file needs the module being opened.).
https://github.com/llvm/llvm-project/pull/80354
More information about the flang-commits
mailing list