[flang-commits] [flang] aea94c9 - [flang] Adjust checks of ICHAR/IACHAR argument length (#72312)
via flang-commits
flang-commits at lists.llvm.org
Thu Nov 30 11:15:40 PST 2023
Author: Peter Klausler
Date: 2023-11-30T11:15:34-08:00
New Revision: aea94c90b39b2694f3a1b2f23f06f005c9d3459b
URL: https://github.com/llvm/llvm-project/commit/aea94c90b39b2694f3a1b2f23f06f005c9d3459b
DIFF: https://github.com/llvm/llvm-project/commit/aea94c90b39b2694f3a1b2f23f06f005c9d3459b.diff
LOG: [flang] Adjust checks of ICHAR/IACHAR argument length (#72312)
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.
Added:
flang/test/Semantics/ichar01.f90
Modified:
flang/lib/Evaluate/fold-integer.cpp
Removed:
################################################################################
diff --git a/flang/lib/Evaluate/fold-integer.cpp b/flang/lib/Evaluate/fold-integer.cpp
index 2882369105f6626..c60648fb195f22e 100644
--- a/flang/lib/Evaluate/fold-integer.cpp
+++ b/flang/lib/Evaluate/fold-integer.cpp
@@ -677,10 +677,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
+
More information about the flang-commits
mailing list