Skip to content

Conversation

@inaki-amatria
Copy link
Member

@inaki-amatria inaki-amatria commented Oct 31, 2024

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.

@github-actions
Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels Oct 31, 2024
@llvmbot
Copy link
Member

llvmbot commented Oct 31, 2024

@llvm/pr-subscribers-flang-semantics

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

Changes

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

@clementval clementval requested a review from klausler October 31, 2024 16:01
@klausler
Copy link
Contributor

klausler commented Nov 1, 2024

A module file with an incorrect checksum might still be valid or useful, so I didn't want the error to be fatal. Sometimes it is useful (but dangerous) to be able to modify a module file by hand.

If you must turn these warnings into unconditional errors, then Fortran::common::UsageWarning::ModuleFile will become obsolete and should be deleted.

@inaki-amatria
Copy link
Member Author

A module file with an incorrect checksum might still be valid or useful, so I didn't want the error to be fatal. Sometimes it is useful (but dangerous) to be able to modify a module file by hand.

Thank you for the feedback, klausler! I believe there is a slight mismatch in the current code's behavior and the intent described here. Even if Flang does not report this error specifically, nullptr is still returned, which prevents the module file with the incorrect checksum from being imported. This ultimately results in a semantics error along the lines of "symbol 'xyz' does not exist". In my opinion, reporting the specific error from ModuleFileReader::Read() offers a clearer and more precise message than a general missing symbol error.

If you must turn these warnings into unconditional errors, then Fortran::common::UsageWarning::ModuleFile will become obsolete and should be deleted.

I have added a fixup commit removing Fortran::common::UsageWarning::ModuleFile and its uses.

Thanks again for the review! Please feel free to close or merge the PR if you are in agreement.

`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.
@inaki-amatria
Copy link
Member Author

I have squashed the commits and updated the branch to be up-to-date with the latest main. Could someone with write access kindly merge this PR for me, as I don't have the necessary permissions? Thanks so much!!

@klausler
Copy link
Contributor

klausler commented Nov 5, 2024

I have squashed the commits and updated the branch to be up-to-date with the latest main. Could someone with write access kindly merge this PR for me, as I don't have the necessary permissions? Thanks so much!!

Please get commit privileges to LLVM for yourself, if possible.

@inaki-amatria inaki-amatria merged commit 0e907c1 into llvm:main Nov 6, 2024
7 checks passed
@github-actions
Copy link

github-actions bot commented Nov 6, 2024

@inaki-amatria Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail here.

If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!

@inaki-amatria inaki-amatria deleted the prevent-errors-from-being-suppressed branch November 6, 2024 07:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

flang:semantics flang Flang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants