[flang-commits] [flang] [flang] Prevent errors from being suppressed (PR #114420)
Iñaki Amatria Barral via flang-commits
flang-commits at lists.llvm.org
Thu Oct 31 08:58:53 PDT 2024
https://github.com/inaki-amatria created https://github.com/llvm/llvm-project/pull/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.
>From c9e3cbe5213d2d6298a1714c884f97cfa069002e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?I=C3=B1aki=20Amatria=20Barral?= <inaki.amatria at appentra.com>
Date: Thu, 31 Oct 2024 16:52:19 +0100
Subject: [PATCH] [flang] Prevent errors from being suppressed
`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.
---
flang/lib/Semantics/mod-file.cpp | 16 +++++-----------
flang/test/Semantics/Inputs/modfile70.mod | 5 +++++
flang/test/Semantics/modfile63.f90 | 2 +-
flang/test/Semantics/modfile70.f90 | 5 +++++
4 files changed, 16 insertions(+), 12 deletions(-)
create mode 100644 flang/test/Semantics/Inputs/modfile70.mod
create mode 100644 flang/test/Semantics/modfile70.f90
diff --git a/flang/lib/Semantics/mod-file.cpp b/flang/lib/Semantics/mod-file.cpp
index 075f33cb684885..c0065045ebee0b 100644
--- a/flang/lib/Semantics/mod-file.cpp
+++ b/flang/lib/Semantics/mod-file.cpp
@@ -1480,19 +1480,13 @@ Scope *ModFileReader::Read(SourceName name, std::optional<bool> isIntrinsic,
std::optional<ModuleCheckSumType> checkSum{
VerifyHeader(sourceFile->content())};
if (!checkSum) {
- if (context_.ShouldWarn(common::UsageWarning::ModuleFile)) {
- Say(name, ancestorName, "File has invalid checksum: %s"_warn_en_US,
- sourceFile->path())
- .set_usageWarning(common::UsageWarning::ModuleFile);
- }
+ Say(name, ancestorName, "File has invalid checksum: %s"_err_en_US,
+ sourceFile->path());
return nullptr;
} else if (requiredHash && *requiredHash != *checkSum) {
- if (context_.ShouldWarn(common::UsageWarning::ModuleFile)) {
- Say(name, ancestorName,
- "File is not the right module file for %s"_warn_en_US,
- "'"s + name.ToString() + "': "s + sourceFile->path())
- .set_usageWarning(common::UsageWarning::ModuleFile);
- }
+ Say(name, ancestorName,
+ "File is not the right module file for %s"_err_en_US,
+ "'"s + name.ToString() + "': "s + sourceFile->path());
return nullptr;
}
llvm::raw_null_ostream NullStream;
diff --git a/flang/test/Semantics/Inputs/modfile70.mod b/flang/test/Semantics/Inputs/modfile70.mod
new file mode 100644
index 00000000000000..14cb3dcde66a28
--- /dev/null
+++ b/flang/test/Semantics/Inputs/modfile70.mod
@@ -0,0 +1,5 @@
+!mod$ v1 sum:invalid_checksum
+module modfile70
+ ! This module file intentionally contains an invalid checksum to trigger a
+ ! semantic error
+end
diff --git a/flang/test/Semantics/modfile63.f90 b/flang/test/Semantics/modfile63.f90
index 0783121017243e..ea8e11958ed8b5 100644
--- a/flang/test/Semantics/modfile63.f90
+++ b/flang/test/Semantics/modfile63.f90
@@ -1,5 +1,5 @@
! RUN: %flang_fc1 -fsyntax-only -I%S/Inputs/dir1 %s
-! RUN: not %flang_fc1 -fsyntax-only -I%S/Inputs/dir2 %s 2>&1 | FileCheck --check-prefix=ERROR %s
+! RUN: not %flang_fc1 -fsyntax-only -I%S/Inputs/dir2 -w %s 2>&1 | FileCheck --check-prefix=ERROR %s
! RUN: %flang_fc1 -Werror -fsyntax-only -I%S/Inputs/dir1 -I%S/Inputs/dir2 %s
! Inputs/dir1 and Inputs/dir2 each have identical copies of modfile63b.mod.
diff --git a/flang/test/Semantics/modfile70.f90 b/flang/test/Semantics/modfile70.f90
new file mode 100644
index 00000000000000..ab387bbf0db689
--- /dev/null
+++ b/flang/test/Semantics/modfile70.f90
@@ -0,0 +1,5 @@
+ use modfile70
+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:
More information about the flang-commits
mailing list