[flang-commits] [flang] [flang] Update to: Adjust checks of ICHAR/IACHAR argument length (PR #73972)

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Thu Nov 30 11:22:40 PST 2023


https://github.com/klausler created https://github.com/llvm/llvm-project/pull/73972

When applying ICHAR/IACHAR to a character constant with length greater than one, resize the character constant to its first character.

>From 4e764ddf42a8f1ac14009914eb624ad124f321ab Mon Sep 17 00:00:00 2001
From: Peter Klausler <pklausler at nvidia.com>
Date: Tue, 14 Nov 2023 13:28:59 -0800
Subject: [PATCH] [flang] Update to: Adjust checks of ICHAR/IACHAR argument
 length

When applying ICHAR/IACHAR to a character constant with length
greater than one, resize the character constant to its first
character.
---
 flang/lib/Evaluate/fold-integer.cpp | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/flang/lib/Evaluate/fold-integer.cpp b/flang/lib/Evaluate/fold-integer.cpp
index c60648fb195f22e..ba4bc6a04750ff7 100644
--- a/flang/lib/Evaluate/fold-integer.cpp
+++ b/flang/lib/Evaluate/fold-integer.cpp
@@ -697,7 +697,8 @@ Expr<Type<TypeCategory::Integer, KIND>> FoldIntrinsicFunction(
                   ScalarFunc<T, Char>(
 #ifndef _MSC_VER
                       [&FromInt64](const Scalar<Char> &c) {
-                        return FromInt64(CharacterUtils<Char::kind>::ICHAR(c));
+                        return FromInt64(CharacterUtils<Char::kind>::ICHAR(
+                            CharacterUtils<Char::kind>::Resize(c, 1)));
                       }));
 #else // _MSC_VER
       // MSVC 14 get confused by the original code above and
@@ -707,7 +708,8 @@ Expr<Type<TypeCategory::Integer, KIND>> FoldIntrinsicFunction(
       // so remove the FromInt64 error checking lambda that
       // seems to have caused the proble.
                       [](const Scalar<Char> &c) {
-                        return CharacterUtils<Char::kind>::ICHAR(c);
+                        return CharacterUtils<Char::kind>::ICHAR(
+                            CharacterUtils<Char::kind>::Resize(c, 1));
                       }));
 #endif // _MSC_VER
             },



More information about the flang-commits mailing list