Skip to content

Commit 9629f2c

Browse files
authored
[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.
1 parent 4a3e4b9 commit 9629f2c

File tree

9 files changed

+23
-22
lines changed

9 files changed

+23
-22
lines changed

flang/lib/Semantics/mod-file.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ void ModFileWriter::Write(const Symbol &symbol) {
139139
const auto *ancestor{module.ancestor()};
140140
isSubmodule_ = ancestor != nullptr;
141141
auto ancestorName{ancestor ? ancestor->GetName().value().ToString() : ""s};
142-
auto path{context_.moduleDirectory() + '/' +
142+
std::string path{context_.moduleDirectory() + '/' +
143143
ModFileName(symbol.name(), ancestorName, context_.moduleFileSuffix())};
144144

145145
UnorderedSymbolSet hermeticModules;
@@ -1392,7 +1392,8 @@ Scope *ModFileReader::Read(SourceName name, std::optional<bool> isIntrinsic,
13921392
// USE, NON_INTRINSIC global name isn't a module?
13931393
fatalError = isIntrinsic.has_value();
13941394
}
1395-
auto path{ModFileName(name, ancestorName, context_.moduleFileSuffix())};
1395+
std::string path{
1396+
ModFileName(name, ancestorName, context_.moduleFileSuffix())};
13961397
parser::Parsing parsing{context_.allCookedSources()};
13971398
parser::Options options;
13981399
options.isModuleFile = true;
@@ -1468,7 +1469,7 @@ Scope *ModFileReader::Read(SourceName name, std::optional<bool> isIntrinsic,
14681469
} else {
14691470
for (auto &msg : parsing.messages().messages()) {
14701471
std::string str{msg.ToString()};
1471-
Say(name, ancestorName,
1472+
Say("parse", name, ancestorName,
14721473
parser::MessageFixedText{str.c_str(), str.size(), msg.severity()},
14731474
path);
14741475
}
@@ -1480,11 +1481,11 @@ Scope *ModFileReader::Read(SourceName name, std::optional<bool> isIntrinsic,
14801481
std::optional<ModuleCheckSumType> checkSum{
14811482
VerifyHeader(sourceFile->content())};
14821483
if (!checkSum) {
1483-
Say(name, ancestorName, "File has invalid checksum: %s"_err_en_US,
1484+
Say("use", name, ancestorName, "File has invalid checksum: %s"_err_en_US,
14841485
sourceFile->path());
14851486
return nullptr;
14861487
} else if (requiredHash && *requiredHash != *checkSum) {
1487-
Say(name, ancestorName,
1488+
Say("use", name, ancestorName,
14881489
"File is not the right module file for %s"_err_en_US,
14891490
"'"s + name.ToString() + "': "s + sourceFile->path());
14901491
return nullptr;
@@ -1494,7 +1495,7 @@ Scope *ModFileReader::Read(SourceName name, std::optional<bool> isIntrinsic,
14941495
std::optional<parser::Program> &parsedProgram{parsing.parseTree()};
14951496
if (!parsing.messages().empty() || !parsing.consumedWholeFile() ||
14961497
!parsedProgram) {
1497-
Say(name, ancestorName, "Module file is corrupt: %s"_err_en_US,
1498+
Say("parse", name, ancestorName, "Module file is corrupt: %s"_err_en_US,
14981499
sourceFile->path());
14991500
return nullptr;
15001501
}
@@ -1572,10 +1573,10 @@ Scope *ModFileReader::Read(SourceName name, std::optional<bool> isIntrinsic,
15721573
}
15731574
}
15741575

1575-
parser::Message &ModFileReader::Say(SourceName name,
1576+
parser::Message &ModFileReader::Say(const char *verb, SourceName name,
15761577
const std::string &ancestor, parser::MessageFixedText &&msg,
15771578
const std::string &arg) {
1578-
return context_.Say(name, "Cannot read module file for %s: %s"_err_en_US,
1579+
return context_.Say(name, "Cannot %s module file for %s: %s"_err_en_US, verb,
15791580
parser::MessageFormattedText{ancestor.empty()
15801581
? "module '%s'"_en_US
15811582
: "submodule '%s' of module '%s'"_en_US,

flang/lib/Semantics/mod-file.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class ModFileReader {
102102
private:
103103
SemanticsContext &context_;
104104

105-
parser::Message &Say(SourceName, const std::string &,
105+
parser::Message &Say(const char *verb, SourceName, const std::string &,
106106
parser::MessageFixedText &&, const std::string &);
107107
};
108108

flang/test/Driver/intrinsic-module-path.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
! WITHOUT-NOT: 'ieee_arithmetic.mod' was not found
1313
! WITHOUT-NOT: 'iso_fortran_env.mod' was not found
1414

15-
! GIVEN: error: Cannot read module file for module 'ieee_arithmetic': File has invalid checksum
16-
! GIVEN: error: Cannot read module file for module 'iso_fortran_env': File has invalid checksum
15+
! GIVEN: error: Cannot use module file for module 'ieee_arithmetic': File has invalid checksum
16+
! GIVEN: error: Cannot use module file for module 'iso_fortran_env': File has invalid checksum
1717

1818

1919
program test_intrinsic_module_path

flang/test/Driver/use-module.f90

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@
3232

3333
! INCLUDED-NOT: error
3434

35-
! MISSING_MOD2-NOT:error: Cannot read module file for module 'basictestmoduleone''
35+
! MISSING_MOD2-NOT:error: Cannot parse module file for module 'basictestmoduleone''
3636
! MISSING_MOD2-NOT:error: Derived type 't1' not found
37-
! MISSING_MOD2:error: Cannot read module file for module 'basictestmoduletwo'
37+
! MISSING_MOD2:error: Cannot parse module file for module 'basictestmoduletwo'
3838
! MISSING_MOD2:error: Derived type 't2' not found
3939

40-
! SINGLEINCLUDE-NOT:error: Cannot read module file for module 'basictestmoduleone'
40+
! SINGLEINCLUDE-NOT:error: Cannot parse module file for module 'basictestmoduleone'
4141
! SINGLEINCLUDE:error: Derived type 't1' not found
42-
! SINGLEINCLUDE-NOT:error: Cannot read module file for module 'basictestmoduletwo'
42+
! SINGLEINCLUDE-NOT:error: Cannot parse module file for module 'basictestmoduletwo'
4343
! SINGLEINCLUDE-NOT:error: Derived type 't2' not found
4444

4545

flang/test/Semantics/modfile43.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ module m4
1818
use :: iso_fortran_env, only: user_defined_123
1919
end module
2020
module m5
21-
!ERROR: Cannot read module file for module 'ieee_arithmetic': Source file 'ieee_arithmetic.mod' was not found
21+
!ERROR: Cannot parse module file for module 'ieee_arithmetic': Source file 'ieee_arithmetic.mod' was not found
2222
use, non_intrinsic :: ieee_arithmetic, only: ieee_selected_real_kind
2323
end module
2424
module notAnIntrinsicModule
2525
end module
2626
module m6
27-
!ERROR: Cannot read module file for module 'notanintrinsicmodule': Source file 'notanintrinsicmodule.mod' was not found
27+
!ERROR: Cannot parse module file for module 'notanintrinsicmodule': Source file 'notanintrinsicmodule.mod' was not found
2828
use, intrinsic :: notAnIntrinsicModule
2929
end module
3030

flang/test/Semantics/modfile63.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
call s2
1414
end
1515

16-
! ERROR: Cannot read module file for module 'modfile63a': File is not the right module file for 'modfile63a':
16+
! ERROR: Cannot use module file for module 'modfile63a': File is not the right module file for 'modfile63a':

flang/test/Semantics/modfile70.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
end
33

44
! RUN: not %flang_fc1 -fsyntax-only -J%S/Inputs -w %s 2>&1 | FileCheck --check-prefix=ERROR %s
5-
! ERROR: Cannot read module file for module 'modfile70': File has invalid checksum:
5+
! ERROR: Cannot use module file for module 'modfile70': File has invalid checksum:

flang/test/Semantics/resolve12.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ subroutine sub
66
end
77

88
use m1
9-
!ERROR: Cannot read module file for module 'm2': Source file 'm2.mod' was not found
9+
!ERROR: Cannot parse module file for module 'm2': Source file 'm2.mod' was not found
1010
use m2
1111
!ERROR: 'sub' is not a module
1212
use sub

flang/test/Semantics/resolve26.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ module subroutine s()
1616
submodule(m1) s1
1717
end
1818

19-
!ERROR: Cannot read module file for submodule 's1' of module 'm2': Source file 'm2-s1.mod' was not found
19+
!ERROR: Cannot parse module file for submodule 's1' of module 'm2': Source file 'm2-s1.mod' was not found
2020
submodule(m2:s1) s2
2121
end
2222

23-
!ERROR: Cannot read module file for module 'm3': Source file 'm3.mod' was not found
23+
!ERROR: Cannot parse module file for module 'm3': Source file 'm3.mod' was not found
2424
submodule(m3:s1) s3
2525
end

0 commit comments

Comments
 (0)