[flang] Improve module file error message wording (#122787)

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.
This commit is contained in:
Peter Klausler
2025-01-14 13:01:56 -08:00
committed by GitHub
parent 4a3e4b99b9
commit 9629f2c4ca
9 changed files with 23 additions and 22 deletions

View File

@@ -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,

View File

@@ -102,7 +102,7 @@ public:
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 &);
};

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -13,4 +13,4 @@ use modfile63b
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':

View File

@@ -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:

View File

@@ -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

View File

@@ -16,10 +16,10 @@ end
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