Skip to content

Commit 0e907c1

Browse files
[flang] Prevent errors from being suppressed (#114420)
`ModFileReader::Say()` flags all messages as errors, but Flang was mistakenly suppressing two errors when the `-w` flag was used, as they were incorrectly conditioned to warning suppression. This fix ensures that errors are reported regardless of the `-w` flag. This commit also replaces two uses of `_warn_en_US` with `_err_en_US` to prevent potential confusion in the future.
1 parent 5adb5c0 commit 0e907c1

File tree

6 files changed

+20
-18
lines changed

6 files changed

+20
-18
lines changed

flang/include/flang/Common/Fortran-features.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,10 @@ ENUM_CLASS(UsageWarning, Portability, PointerToUndefinable,
6767
Bounds, Preprocessing, Scanning, OpenAccUsage, ProcPointerCompatibility,
6868
VoidMold, KnownBadImplicitInterface, EmptyCase, CaseOverflow, CUDAUsage,
6969
IgnoreTKRUsage, ExternalInterfaceMismatch, DefinedOperatorArgs, Final,
70-
ZeroDoStep, UnusedForallIndex, OpenMPUsage, ModuleFile, DataLength,
71-
IgnoredDirective, HomonymousSpecific, HomonymousResult,
72-
IgnoredIntrinsicFunctionType, PreviousScalarUse,
73-
RedeclaredInaccessibleComponent, ImplicitShared, IndexVarRedefinition,
74-
IncompatibleImplicitInterfaces, BadTypeForTarget,
70+
ZeroDoStep, UnusedForallIndex, OpenMPUsage, DataLength, IgnoredDirective,
71+
HomonymousSpecific, HomonymousResult, IgnoredIntrinsicFunctionType,
72+
PreviousScalarUse, RedeclaredInaccessibleComponent, ImplicitShared,
73+
IndexVarRedefinition, IncompatibleImplicitInterfaces, BadTypeForTarget,
7574
VectorSubscriptFinalization, UndefinedFunctionResult, UselessIomsg,
7675
MismatchingDummyProcedure)
7776

flang/lib/Common/Fortran-features.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ LanguageFeatureControl::LanguageFeatureControl() {
6666
warnUsage_.set(UsageWarning::ZeroDoStep);
6767
warnUsage_.set(UsageWarning::UnusedForallIndex);
6868
warnUsage_.set(UsageWarning::OpenMPUsage);
69-
warnUsage_.set(UsageWarning::ModuleFile);
7069
warnUsage_.set(UsageWarning::DataLength);
7170
warnUsage_.set(UsageWarning::IgnoredDirective);
7271
warnUsage_.set(UsageWarning::HomonymousSpecific);

flang/lib/Semantics/mod-file.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1480,19 +1480,13 @@ Scope *ModFileReader::Read(SourceName name, std::optional<bool> isIntrinsic,
14801480
std::optional<ModuleCheckSumType> checkSum{
14811481
VerifyHeader(sourceFile->content())};
14821482
if (!checkSum) {
1483-
if (context_.ShouldWarn(common::UsageWarning::ModuleFile)) {
1484-
Say(name, ancestorName, "File has invalid checksum: %s"_warn_en_US,
1485-
sourceFile->path())
1486-
.set_usageWarning(common::UsageWarning::ModuleFile);
1487-
}
1483+
Say(name, ancestorName, "File has invalid checksum: %s"_err_en_US,
1484+
sourceFile->path());
14881485
return nullptr;
14891486
} else if (requiredHash && *requiredHash != *checkSum) {
1490-
if (context_.ShouldWarn(common::UsageWarning::ModuleFile)) {
1491-
Say(name, ancestorName,
1492-
"File is not the right module file for %s"_warn_en_US,
1493-
"'"s + name.ToString() + "': "s + sourceFile->path())
1494-
.set_usageWarning(common::UsageWarning::ModuleFile);
1495-
}
1487+
Say(name, ancestorName,
1488+
"File is not the right module file for %s"_err_en_US,
1489+
"'"s + name.ToString() + "': "s + sourceFile->path());
14961490
return nullptr;
14971491
}
14981492
llvm::raw_null_ostream NullStream;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
!mod$ v1 sum:invalid_checksum
2+
module modfile70
3+
! This module file intentionally contains an invalid checksum to trigger a
4+
! semantic error
5+
end

flang/test/Semantics/modfile63.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
! RUN: %flang_fc1 -fsyntax-only -I%S/Inputs/dir1 %s
2-
! RUN: not %flang_fc1 -fsyntax-only -I%S/Inputs/dir2 %s 2>&1 | FileCheck --check-prefix=ERROR %s
2+
! RUN: not %flang_fc1 -fsyntax-only -I%S/Inputs/dir2 -w %s 2>&1 | FileCheck --check-prefix=ERROR %s
33
! RUN: %flang_fc1 -Werror -fsyntax-only -I%S/Inputs/dir1 -I%S/Inputs/dir2 %s
44

55
! Inputs/dir1 and Inputs/dir2 each have identical copies of modfile63b.mod.

flang/test/Semantics/modfile70.f90

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
use modfile70
2+
end
3+
4+
! 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:

0 commit comments

Comments
 (0)