Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[flang] Adjust checks of ICHAR/IACHAR argument length #72312

Merged
merged 1 commit into from
Nov 30, 2023

Conversation

klausler
Copy link
Contributor

The compiler will now emit an error for length == 0 and an off-by-default portability warning for length > 1. Previously, the message was an unconditional warning for length /= 1.

The compiler will now emit an error for length == 0 and an
off-by-default portability warning for length > 1.  Previously,
the message was an unconditional warning for length /= 1.
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels Nov 14, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Nov 14, 2023

@llvm/pr-subscribers-flang-semantics

Author: Peter Klausler (klausler)

Changes

The compiler will now emit an error for length == 0 and an off-by-default portability warning for length > 1. Previously, the message was an unconditional warning for length /= 1.


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

2 Files Affected:

  • (modified) flang/lib/Evaluate/fold-integer.cpp (+8-2)
  • (added) flang/test/Semantics/ichar01.f90 (+13)
diff --git a/flang/lib/Evaluate/fold-integer.cpp b/flang/lib/Evaluate/fold-integer.cpp
index dedfc20a491cd88..489102f5277f1f0 100644
--- a/flang/lib/Evaluate/fold-integer.cpp
+++ b/flang/lib/Evaluate/fold-integer.cpp
@@ -676,10 +676,16 @@ Expr<Type<TypeCategory::Integer, KIND>> FoldIntrinsicFunction(
     auto *someChar{UnwrapExpr<Expr<SomeCharacter>>(args[0])};
     CHECK(someChar);
     if (auto len{ToInt64(someChar->LEN())}) {
-      if (len.value() != 1) {
+      if (len.value() < 1) {
+        context.messages().Say(
+            "Character in intrinsic function %s must have length one"_err_en_US,
+            name);
+      } else if (len.value() > 1 &&
+          context.languageFeatures().ShouldWarn(
+              common::UsageWarning::Portability)) {
         // Do not die, this was not checked before
         context.messages().Say(
-            "Character in intrinsic function %s must have length one"_warn_en_US,
+            "Character in intrinsic function %s should have length one"_port_en_US,
             name);
       } else {
         return common::visit(
diff --git a/flang/test/Semantics/ichar01.f90 b/flang/test/Semantics/ichar01.f90
new file mode 100644
index 000000000000000..5eb25a97e6d939e
--- /dev/null
+++ b/flang/test/Semantics/ichar01.f90
@@ -0,0 +1,13 @@
+! RUN: %python %S/test_errors.py %s %flang_fc1 -pedantic
+!ERROR: Character in intrinsic function ichar must have length one
+print *, ichar('')
+!ERROR: Character in intrinsic function iachar must have length one
+print *, iachar('')
+print *, ichar('a')
+print *, iachar('a')
+!PORTABILITY: Character in intrinsic function ichar should have length one
+print *, ichar('ab')
+!PORTABILITY: Character in intrinsic function iachar should have length one
+print *, iachar('ab')
+end
+

@klausler klausler merged commit aea94c9 into llvm:main Nov 30, 2023
5 checks passed
@klausler klausler deleted the bug1432 branch November 30, 2023 19:15
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.

None yet

3 participants