[flang-commits] [flang] [flang] Prevent errors from being suppressed (PR #114420)

via flang-commits flang-commits at lists.llvm.org
Thu Oct 31 08:59:45 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-semantics

Author: Iñaki Amatria Barral (inaki-amatria)

<details>
<summary>Changes</summary>

`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.

---
Full diff: https://github.com/llvm/llvm-project/pull/114420.diff


4 Files Affected:

- (modified) flang/lib/Semantics/mod-file.cpp (+5-11) 
- (added) flang/test/Semantics/Inputs/modfile70.mod (+5) 
- (modified) flang/test/Semantics/modfile63.f90 (+1-1) 
- (added) flang/test/Semantics/modfile70.f90 (+5) 


``````````diff
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:

``````````

</details>


https://github.com/llvm/llvm-project/pull/114420


More information about the flang-commits mailing list