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

via flang-commits flang-commits at lists.llvm.org
Tue Nov 5 23:23:31 PST 2024


Author: Iñaki Amatria Barral
Date: 2024-11-06T08:23:26+01:00
New Revision: 0e907c17214aa3b1a60b66867fea3cc0f0dcbaa0

URL: https://github.com/llvm/llvm-project/commit/0e907c17214aa3b1a60b66867fea3cc0f0dcbaa0
DIFF: https://github.com/llvm/llvm-project/commit/0e907c17214aa3b1a60b66867fea3cc0f0dcbaa0.diff

LOG: [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.

Added: 
    flang/test/Semantics/Inputs/modfile70.mod
    flang/test/Semantics/modfile70.f90

Modified: 
    flang/include/flang/Common/Fortran-features.h
    flang/lib/Common/Fortran-features.cpp
    flang/lib/Semantics/mod-file.cpp
    flang/test/Semantics/modfile63.f90

Removed: 
    


################################################################################
diff  --git a/flang/include/flang/Common/Fortran-features.h b/flang/include/flang/Common/Fortran-features.h
index 2b57c7ae50642c..74edbe44fdbb1c 100644
--- a/flang/include/flang/Common/Fortran-features.h
+++ b/flang/include/flang/Common/Fortran-features.h
@@ -67,11 +67,10 @@ ENUM_CLASS(UsageWarning, Portability, PointerToUndefinable,
     Bounds, Preprocessing, Scanning, OpenAccUsage, ProcPointerCompatibility,
     VoidMold, KnownBadImplicitInterface, EmptyCase, CaseOverflow, CUDAUsage,
     IgnoreTKRUsage, ExternalInterfaceMismatch, DefinedOperatorArgs, Final,
-    ZeroDoStep, UnusedForallIndex, OpenMPUsage, ModuleFile, DataLength,
-    IgnoredDirective, HomonymousSpecific, HomonymousResult,
-    IgnoredIntrinsicFunctionType, PreviousScalarUse,
-    RedeclaredInaccessibleComponent, ImplicitShared, IndexVarRedefinition,
-    IncompatibleImplicitInterfaces, BadTypeForTarget,
+    ZeroDoStep, UnusedForallIndex, OpenMPUsage, DataLength, IgnoredDirective,
+    HomonymousSpecific, HomonymousResult, IgnoredIntrinsicFunctionType,
+    PreviousScalarUse, RedeclaredInaccessibleComponent, ImplicitShared,
+    IndexVarRedefinition, IncompatibleImplicitInterfaces, BadTypeForTarget,
     VectorSubscriptFinalization, UndefinedFunctionResult, UselessIomsg,
     MismatchingDummyProcedure)
 

diff  --git a/flang/lib/Common/Fortran-features.cpp b/flang/lib/Common/Fortran-features.cpp
index a53f32d74dc37d..fff796e42552a5 100644
--- a/flang/lib/Common/Fortran-features.cpp
+++ b/flang/lib/Common/Fortran-features.cpp
@@ -66,7 +66,6 @@ LanguageFeatureControl::LanguageFeatureControl() {
   warnUsage_.set(UsageWarning::ZeroDoStep);
   warnUsage_.set(UsageWarning::UnusedForallIndex);
   warnUsage_.set(UsageWarning::OpenMPUsage);
-  warnUsage_.set(UsageWarning::ModuleFile);
   warnUsage_.set(UsageWarning::DataLength);
   warnUsage_.set(UsageWarning::IgnoredDirective);
   warnUsage_.set(UsageWarning::HomonymousSpecific);

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