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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions flang/lib/Semantics/mod-file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand All @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion flang/lib/Semantics/mod-file.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 &);
};

Expand Down
4 changes: 2 additions & 2 deletions flang/test/Driver/intrinsic-module-path.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions flang/test/Driver/use-module.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
4 changes: 2 additions & 2 deletions flang/test/Semantics/modfile43.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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

2 changes: 1 addition & 1 deletion flang/test/Semantics/modfile63.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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':
2 changes: 1 addition & 1 deletion flang/test/Semantics/modfile70.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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:
2 changes: 1 addition & 1 deletion flang/test/Semantics/resolve12.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions flang/test/Semantics/resolve26.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading