Skip to content

[flang] Improve module file error message wording #122787

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 14, 2025

Conversation

klausler
Copy link
Contributor

Instead of "Cannot read ...", distinguish true errors in finding and parsing module files from problems with unexpected hash codes by using "Cannot parse" or "Cannot use" wording as appropriate.

Instead of "Cannot read ...", distinguish true errors in
finding and parsing module files from problems with unexpected
hash codes by using "Cannot parse" or "Cannot use" wording
as appropriate.
@llvmbot llvmbot added flang:driver flang Flang issues not falling into any other category flang:semantics labels Jan 13, 2025
@llvmbot
Copy link
Member

llvmbot commented Jan 13, 2025

@llvm/pr-subscribers-flang-driver

Author: Peter Klausler (klausler)

Changes

Instead of "Cannot read ...", distinguish true errors in finding and parsing module files from problems with unexpected hash codes by using "Cannot parse" or "Cannot use" wording as appropriate.


Full diff: https://github.com/llvm/llvm-project/pull/122787.diff

9 Files Affected:

  • (modified) flang/lib/Semantics/mod-file.cpp (+9-8)
  • (modified) flang/lib/Semantics/mod-file.h (+1-1)
  • (modified) flang/test/Driver/intrinsic-module-path.f90 (+2-2)
  • (modified) flang/test/Driver/use-module.f90 (+4-4)
  • (modified) flang/test/Semantics/modfile43.f90 (+2-2)
  • (modified) flang/test/Semantics/modfile63.f90 (+1-1)
  • (modified) flang/test/Semantics/modfile70.f90 (+1-1)
  • (modified) flang/test/Semantics/resolve12.f90 (+1-1)
  • (modified) flang/test/Semantics/resolve26.f90 (+2-2)
diff --git a/flang/lib/Semantics/mod-file.cpp b/flang/lib/Semantics/mod-file.cpp
index c0065045ebee0b..51ff70c3ed8341 100644
--- a/flang/lib/Semantics/mod-file.cpp
+++ b/flang/lib/Semantics/mod-file.cpp
@@ -139,7 +139,7 @@ void ModFileWriter::Write(const Symbol &symbol) {
   const auto *ancestor{module.ancestor()};
   isSubmodule_ = ancestor != nullptr;
   auto ancestorName{ancestor ? ancestor->GetName().value().ToString() : ""s};
-  auto path{context_.moduleDirectory() + '/' +
+  std::string path{context_.moduleDirectory() + '/' +
       ModFileName(symbol.name(), ancestorName, context_.moduleFileSuffix())};
 
   UnorderedSymbolSet hermeticModules;
@@ -1392,7 +1392,8 @@ Scope *ModFileReader::Read(SourceName name, std::optional<bool> isIntrinsic,
     // USE, NON_INTRINSIC global name isn't a module?
     fatalError = isIntrinsic.has_value();
   }
-  auto path{ModFileName(name, ancestorName, context_.moduleFileSuffix())};
+  std::string path{
+      ModFileName(name, ancestorName, context_.moduleFileSuffix())};
   parser::Parsing parsing{context_.allCookedSources()};
   parser::Options options;
   options.isModuleFile = true;
@@ -1468,7 +1469,7 @@ Scope *ModFileReader::Read(SourceName name, std::optional<bool> isIntrinsic,
       } else {
         for (auto &msg : parsing.messages().messages()) {
           std::string str{msg.ToString()};
-          Say(name, ancestorName,
+          Say("parse", name, ancestorName,
               parser::MessageFixedText{str.c_str(), str.size(), msg.severity()},
               path);
         }
@@ -1480,11 +1481,11 @@ Scope *ModFileReader::Read(SourceName name, std::optional<bool> isIntrinsic,
   std::optional<ModuleCheckSumType> checkSum{
       VerifyHeader(sourceFile->content())};
   if (!checkSum) {
-    Say(name, ancestorName, "File has invalid checksum: %s"_err_en_US,
+    Say("use", name, ancestorName, "File has invalid checksum: %s"_err_en_US,
         sourceFile->path());
     return nullptr;
   } else if (requiredHash && *requiredHash != *checkSum) {
-    Say(name, ancestorName,
+    Say("use", name, ancestorName,
         "File is not the right module file for %s"_err_en_US,
         "'"s + name.ToString() + "': "s + sourceFile->path());
     return nullptr;
@@ -1494,7 +1495,7 @@ Scope *ModFileReader::Read(SourceName name, std::optional<bool> isIntrinsic,
   std::optional<parser::Program> &parsedProgram{parsing.parseTree()};
   if (!parsing.messages().empty() || !parsing.consumedWholeFile() ||
       !parsedProgram) {
-    Say(name, ancestorName, "Module file is corrupt: %s"_err_en_US,
+    Say("parse", name, ancestorName, "Module file is corrupt: %s"_err_en_US,
         sourceFile->path());
     return nullptr;
   }
@@ -1572,10 +1573,10 @@ Scope *ModFileReader::Read(SourceName name, std::optional<bool> isIntrinsic,
   }
 }
 
-parser::Message &ModFileReader::Say(SourceName name,
+parser::Message &ModFileReader::Say(const char *verb, SourceName name,
     const std::string &ancestor, parser::MessageFixedText &&msg,
     const std::string &arg) {
-  return context_.Say(name, "Cannot read module file for %s: %s"_err_en_US,
+  return context_.Say(name, "Cannot %s module file for %s: %s"_err_en_US, verb,
       parser::MessageFormattedText{ancestor.empty()
               ? "module '%s'"_en_US
               : "submodule '%s' of module '%s'"_en_US,
diff --git a/flang/lib/Semantics/mod-file.h b/flang/lib/Semantics/mod-file.h
index 49bcef0c923fb4..82538fb510873b 100644
--- a/flang/lib/Semantics/mod-file.h
+++ b/flang/lib/Semantics/mod-file.h
@@ -102,7 +102,7 @@ class ModFileReader {
 private:
   SemanticsContext &context_;
 
-  parser::Message &Say(SourceName, const std::string &,
+  parser::Message &Say(const char *verb, SourceName, const std::string &,
       parser::MessageFixedText &&, const std::string &);
 };
 
diff --git a/flang/test/Driver/intrinsic-module-path.f90 b/flang/test/Driver/intrinsic-module-path.f90
index 15d19dd83d963f..8fe486cf61c832 100644
--- a/flang/test/Driver/intrinsic-module-path.f90
+++ b/flang/test/Driver/intrinsic-module-path.f90
@@ -12,8 +12,8 @@
 ! WITHOUT-NOT: 'ieee_arithmetic.mod' was not found
 ! WITHOUT-NOT: 'iso_fortran_env.mod' was not found
 
-! GIVEN: error: Cannot read module file for module 'ieee_arithmetic': File has invalid checksum
-! GIVEN: error: Cannot read module file for module 'iso_fortran_env': File has invalid checksum
+! GIVEN: error: Cannot use module file for module 'ieee_arithmetic': File has invalid checksum
+! GIVEN: error: Cannot use module file for module 'iso_fortran_env': File has invalid checksum
 
 
 program test_intrinsic_module_path
diff --git a/flang/test/Driver/use-module.f90 b/flang/test/Driver/use-module.f90
index 2c3a38043fe16e..ec650475f0b023 100644
--- a/flang/test/Driver/use-module.f90
+++ b/flang/test/Driver/use-module.f90
@@ -32,14 +32,14 @@
 
 ! INCLUDED-NOT: error
 
-! MISSING_MOD2-NOT:error: Cannot read module file for module 'basictestmoduleone''
+! MISSING_MOD2-NOT:error: Cannot parse module file for module 'basictestmoduleone''
 ! MISSING_MOD2-NOT:error: Derived type 't1' not found
-! MISSING_MOD2:error: Cannot read module file for module 'basictestmoduletwo'
+! MISSING_MOD2:error: Cannot parse module file for module 'basictestmoduletwo'
 ! MISSING_MOD2:error: Derived type 't2' not found
 
-! SINGLEINCLUDE-NOT:error: Cannot read module file for module 'basictestmoduleone'
+! SINGLEINCLUDE-NOT:error: Cannot parse module file for module 'basictestmoduleone'
 ! SINGLEINCLUDE:error: Derived type 't1' not found
-! SINGLEINCLUDE-NOT:error: Cannot read module file for module 'basictestmoduletwo'
+! SINGLEINCLUDE-NOT:error: Cannot parse module file for module 'basictestmoduletwo'
 ! SINGLEINCLUDE-NOT:error: Derived type 't2' not found
 
 
diff --git a/flang/test/Semantics/modfile43.f90 b/flang/test/Semantics/modfile43.f90
index 1629e053c71163..1a50e94698f63e 100644
--- a/flang/test/Semantics/modfile43.f90
+++ b/flang/test/Semantics/modfile43.f90
@@ -18,13 +18,13 @@ module m4
   use :: iso_fortran_env, only: user_defined_123
 end module
 module m5
-  !ERROR: Cannot read module file for module 'ieee_arithmetic': Source file 'ieee_arithmetic.mod' was not found
+  !ERROR: Cannot parse module file for module 'ieee_arithmetic': Source file 'ieee_arithmetic.mod' was not found
   use, non_intrinsic :: ieee_arithmetic, only: ieee_selected_real_kind
 end module
 module notAnIntrinsicModule
 end module
 module m6
-  !ERROR: Cannot read module file for module 'notanintrinsicmodule': Source file 'notanintrinsicmodule.mod' was not found
+  !ERROR: Cannot parse module file for module 'notanintrinsicmodule': Source file 'notanintrinsicmodule.mod' was not found
   use, intrinsic :: notAnIntrinsicModule
 end module
 
diff --git a/flang/test/Semantics/modfile63.f90 b/flang/test/Semantics/modfile63.f90
index ea8e11958ed8b5..167b997443c779 100644
--- a/flang/test/Semantics/modfile63.f90
+++ b/flang/test/Semantics/modfile63.f90
@@ -13,4 +13,4 @@
 call s2
 end
 
-! ERROR: Cannot read module file for module 'modfile63a': File is not the right module file for 'modfile63a':
+! ERROR: Cannot use module file for module 'modfile63a': File is not the right module file for 'modfile63a':
diff --git a/flang/test/Semantics/modfile70.f90 b/flang/test/Semantics/modfile70.f90
index ab387bbf0db689..beb2ec9c9d15d2 100644
--- a/flang/test/Semantics/modfile70.f90
+++ b/flang/test/Semantics/modfile70.f90
@@ -2,4 +2,4 @@
 end
 
 ! RUN: not %flang_fc1 -fsyntax-only -J%S/Inputs -w %s 2>&1 | FileCheck --check-prefix=ERROR %s
-! ERROR: Cannot read module file for module 'modfile70': File has invalid checksum:
+! ERROR: Cannot use module file for module 'modfile70': File has invalid checksum:
diff --git a/flang/test/Semantics/resolve12.f90 b/flang/test/Semantics/resolve12.f90
index aa9dbd7f00603d..dd674c33eab982 100644
--- a/flang/test/Semantics/resolve12.f90
+++ b/flang/test/Semantics/resolve12.f90
@@ -6,7 +6,7 @@ subroutine sub
 end
 
 use m1
-!ERROR: Cannot read module file for module 'm2': Source file 'm2.mod' was not found
+!ERROR: Cannot parse module file for module 'm2': Source file 'm2.mod' was not found
 use m2
 !ERROR: 'sub' is not a module
 use sub
diff --git a/flang/test/Semantics/resolve26.f90 b/flang/test/Semantics/resolve26.f90
index 5e77cc4fbe9a50..a416830e488e71 100644
--- a/flang/test/Semantics/resolve26.f90
+++ b/flang/test/Semantics/resolve26.f90
@@ -16,10 +16,10 @@ module subroutine s()
 submodule(m1) s1
 end
 
-!ERROR: Cannot read module file for submodule 's1' of module 'm2': Source file 'm2-s1.mod' was not found
+!ERROR: Cannot parse module file for submodule 's1' of module 'm2': Source file 'm2-s1.mod' was not found
 submodule(m2:s1) s2
 end
 
-!ERROR: Cannot read module file for module 'm3': Source file 'm3.mod' was not found
+!ERROR: Cannot parse module file for module 'm3': Source file 'm3.mod' was not found
 submodule(m3:s1) s3
 end

@llvmbot
Copy link
Member

llvmbot commented Jan 13, 2025

@llvm/pr-subscribers-flang-semantics

Author: Peter Klausler (klausler)

Changes

Instead of "Cannot read ...", distinguish true errors in finding and parsing module files from problems with unexpected hash codes by using "Cannot parse" or "Cannot use" wording as appropriate.


Full diff: https://github.com/llvm/llvm-project/pull/122787.diff

9 Files Affected:

  • (modified) flang/lib/Semantics/mod-file.cpp (+9-8)
  • (modified) flang/lib/Semantics/mod-file.h (+1-1)
  • (modified) flang/test/Driver/intrinsic-module-path.f90 (+2-2)
  • (modified) flang/test/Driver/use-module.f90 (+4-4)
  • (modified) flang/test/Semantics/modfile43.f90 (+2-2)
  • (modified) flang/test/Semantics/modfile63.f90 (+1-1)
  • (modified) flang/test/Semantics/modfile70.f90 (+1-1)
  • (modified) flang/test/Semantics/resolve12.f90 (+1-1)
  • (modified) flang/test/Semantics/resolve26.f90 (+2-2)
diff --git a/flang/lib/Semantics/mod-file.cpp b/flang/lib/Semantics/mod-file.cpp
index c0065045ebee0b..51ff70c3ed8341 100644
--- a/flang/lib/Semantics/mod-file.cpp
+++ b/flang/lib/Semantics/mod-file.cpp
@@ -139,7 +139,7 @@ void ModFileWriter::Write(const Symbol &symbol) {
   const auto *ancestor{module.ancestor()};
   isSubmodule_ = ancestor != nullptr;
   auto ancestorName{ancestor ? ancestor->GetName().value().ToString() : ""s};
-  auto path{context_.moduleDirectory() + '/' +
+  std::string path{context_.moduleDirectory() + '/' +
       ModFileName(symbol.name(), ancestorName, context_.moduleFileSuffix())};
 
   UnorderedSymbolSet hermeticModules;
@@ -1392,7 +1392,8 @@ Scope *ModFileReader::Read(SourceName name, std::optional<bool> isIntrinsic,
     // USE, NON_INTRINSIC global name isn't a module?
     fatalError = isIntrinsic.has_value();
   }
-  auto path{ModFileName(name, ancestorName, context_.moduleFileSuffix())};
+  std::string path{
+      ModFileName(name, ancestorName, context_.moduleFileSuffix())};
   parser::Parsing parsing{context_.allCookedSources()};
   parser::Options options;
   options.isModuleFile = true;
@@ -1468,7 +1469,7 @@ Scope *ModFileReader::Read(SourceName name, std::optional<bool> isIntrinsic,
       } else {
         for (auto &msg : parsing.messages().messages()) {
           std::string str{msg.ToString()};
-          Say(name, ancestorName,
+          Say("parse", name, ancestorName,
               parser::MessageFixedText{str.c_str(), str.size(), msg.severity()},
               path);
         }
@@ -1480,11 +1481,11 @@ Scope *ModFileReader::Read(SourceName name, std::optional<bool> isIntrinsic,
   std::optional<ModuleCheckSumType> checkSum{
       VerifyHeader(sourceFile->content())};
   if (!checkSum) {
-    Say(name, ancestorName, "File has invalid checksum: %s"_err_en_US,
+    Say("use", name, ancestorName, "File has invalid checksum: %s"_err_en_US,
         sourceFile->path());
     return nullptr;
   } else if (requiredHash && *requiredHash != *checkSum) {
-    Say(name, ancestorName,
+    Say("use", name, ancestorName,
         "File is not the right module file for %s"_err_en_US,
         "'"s + name.ToString() + "': "s + sourceFile->path());
     return nullptr;
@@ -1494,7 +1495,7 @@ Scope *ModFileReader::Read(SourceName name, std::optional<bool> isIntrinsic,
   std::optional<parser::Program> &parsedProgram{parsing.parseTree()};
   if (!parsing.messages().empty() || !parsing.consumedWholeFile() ||
       !parsedProgram) {
-    Say(name, ancestorName, "Module file is corrupt: %s"_err_en_US,
+    Say("parse", name, ancestorName, "Module file is corrupt: %s"_err_en_US,
         sourceFile->path());
     return nullptr;
   }
@@ -1572,10 +1573,10 @@ Scope *ModFileReader::Read(SourceName name, std::optional<bool> isIntrinsic,
   }
 }
 
-parser::Message &ModFileReader::Say(SourceName name,
+parser::Message &ModFileReader::Say(const char *verb, SourceName name,
     const std::string &ancestor, parser::MessageFixedText &&msg,
     const std::string &arg) {
-  return context_.Say(name, "Cannot read module file for %s: %s"_err_en_US,
+  return context_.Say(name, "Cannot %s module file for %s: %s"_err_en_US, verb,
       parser::MessageFormattedText{ancestor.empty()
               ? "module '%s'"_en_US
               : "submodule '%s' of module '%s'"_en_US,
diff --git a/flang/lib/Semantics/mod-file.h b/flang/lib/Semantics/mod-file.h
index 49bcef0c923fb4..82538fb510873b 100644
--- a/flang/lib/Semantics/mod-file.h
+++ b/flang/lib/Semantics/mod-file.h
@@ -102,7 +102,7 @@ class ModFileReader {
 private:
   SemanticsContext &context_;
 
-  parser::Message &Say(SourceName, const std::string &,
+  parser::Message &Say(const char *verb, SourceName, const std::string &,
       parser::MessageFixedText &&, const std::string &);
 };
 
diff --git a/flang/test/Driver/intrinsic-module-path.f90 b/flang/test/Driver/intrinsic-module-path.f90
index 15d19dd83d963f..8fe486cf61c832 100644
--- a/flang/test/Driver/intrinsic-module-path.f90
+++ b/flang/test/Driver/intrinsic-module-path.f90
@@ -12,8 +12,8 @@
 ! WITHOUT-NOT: 'ieee_arithmetic.mod' was not found
 ! WITHOUT-NOT: 'iso_fortran_env.mod' was not found
 
-! GIVEN: error: Cannot read module file for module 'ieee_arithmetic': File has invalid checksum
-! GIVEN: error: Cannot read module file for module 'iso_fortran_env': File has invalid checksum
+! GIVEN: error: Cannot use module file for module 'ieee_arithmetic': File has invalid checksum
+! GIVEN: error: Cannot use module file for module 'iso_fortran_env': File has invalid checksum
 
 
 program test_intrinsic_module_path
diff --git a/flang/test/Driver/use-module.f90 b/flang/test/Driver/use-module.f90
index 2c3a38043fe16e..ec650475f0b023 100644
--- a/flang/test/Driver/use-module.f90
+++ b/flang/test/Driver/use-module.f90
@@ -32,14 +32,14 @@
 
 ! INCLUDED-NOT: error
 
-! MISSING_MOD2-NOT:error: Cannot read module file for module 'basictestmoduleone''
+! MISSING_MOD2-NOT:error: Cannot parse module file for module 'basictestmoduleone''
 ! MISSING_MOD2-NOT:error: Derived type 't1' not found
-! MISSING_MOD2:error: Cannot read module file for module 'basictestmoduletwo'
+! MISSING_MOD2:error: Cannot parse module file for module 'basictestmoduletwo'
 ! MISSING_MOD2:error: Derived type 't2' not found
 
-! SINGLEINCLUDE-NOT:error: Cannot read module file for module 'basictestmoduleone'
+! SINGLEINCLUDE-NOT:error: Cannot parse module file for module 'basictestmoduleone'
 ! SINGLEINCLUDE:error: Derived type 't1' not found
-! SINGLEINCLUDE-NOT:error: Cannot read module file for module 'basictestmoduletwo'
+! SINGLEINCLUDE-NOT:error: Cannot parse module file for module 'basictestmoduletwo'
 ! SINGLEINCLUDE-NOT:error: Derived type 't2' not found
 
 
diff --git a/flang/test/Semantics/modfile43.f90 b/flang/test/Semantics/modfile43.f90
index 1629e053c71163..1a50e94698f63e 100644
--- a/flang/test/Semantics/modfile43.f90
+++ b/flang/test/Semantics/modfile43.f90
@@ -18,13 +18,13 @@ module m4
   use :: iso_fortran_env, only: user_defined_123
 end module
 module m5
-  !ERROR: Cannot read module file for module 'ieee_arithmetic': Source file 'ieee_arithmetic.mod' was not found
+  !ERROR: Cannot parse module file for module 'ieee_arithmetic': Source file 'ieee_arithmetic.mod' was not found
   use, non_intrinsic :: ieee_arithmetic, only: ieee_selected_real_kind
 end module
 module notAnIntrinsicModule
 end module
 module m6
-  !ERROR: Cannot read module file for module 'notanintrinsicmodule': Source file 'notanintrinsicmodule.mod' was not found
+  !ERROR: Cannot parse module file for module 'notanintrinsicmodule': Source file 'notanintrinsicmodule.mod' was not found
   use, intrinsic :: notAnIntrinsicModule
 end module
 
diff --git a/flang/test/Semantics/modfile63.f90 b/flang/test/Semantics/modfile63.f90
index ea8e11958ed8b5..167b997443c779 100644
--- a/flang/test/Semantics/modfile63.f90
+++ b/flang/test/Semantics/modfile63.f90
@@ -13,4 +13,4 @@
 call s2
 end
 
-! ERROR: Cannot read module file for module 'modfile63a': File is not the right module file for 'modfile63a':
+! ERROR: Cannot use module file for module 'modfile63a': File is not the right module file for 'modfile63a':
diff --git a/flang/test/Semantics/modfile70.f90 b/flang/test/Semantics/modfile70.f90
index ab387bbf0db689..beb2ec9c9d15d2 100644
--- a/flang/test/Semantics/modfile70.f90
+++ b/flang/test/Semantics/modfile70.f90
@@ -2,4 +2,4 @@
 end
 
 ! RUN: not %flang_fc1 -fsyntax-only -J%S/Inputs -w %s 2>&1 | FileCheck --check-prefix=ERROR %s
-! ERROR: Cannot read module file for module 'modfile70': File has invalid checksum:
+! ERROR: Cannot use module file for module 'modfile70': File has invalid checksum:
diff --git a/flang/test/Semantics/resolve12.f90 b/flang/test/Semantics/resolve12.f90
index aa9dbd7f00603d..dd674c33eab982 100644
--- a/flang/test/Semantics/resolve12.f90
+++ b/flang/test/Semantics/resolve12.f90
@@ -6,7 +6,7 @@ subroutine sub
 end
 
 use m1
-!ERROR: Cannot read module file for module 'm2': Source file 'm2.mod' was not found
+!ERROR: Cannot parse module file for module 'm2': Source file 'm2.mod' was not found
 use m2
 !ERROR: 'sub' is not a module
 use sub
diff --git a/flang/test/Semantics/resolve26.f90 b/flang/test/Semantics/resolve26.f90
index 5e77cc4fbe9a50..a416830e488e71 100644
--- a/flang/test/Semantics/resolve26.f90
+++ b/flang/test/Semantics/resolve26.f90
@@ -16,10 +16,10 @@ module subroutine s()
 submodule(m1) s1
 end
 
-!ERROR: Cannot read module file for submodule 's1' of module 'm2': Source file 'm2-s1.mod' was not found
+!ERROR: Cannot parse module file for submodule 's1' of module 'm2': Source file 'm2-s1.mod' was not found
 submodule(m2:s1) s2
 end
 
-!ERROR: Cannot read module file for module 'm3': Source file 'm3.mod' was not found
+!ERROR: Cannot parse module file for module 'm3': Source file 'm3.mod' was not found
 submodule(m3:s1) s3
 end

Copy link
Contributor

@akuhlens akuhlens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a strict improvement over the previous error messages.

@klausler klausler merged commit 9629f2c into llvm:main Jan 14, 2025
10 of 12 checks passed
@klausler klausler deleted the better-msg branch January 14, 2025 21:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:driver flang:semantics flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants