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] Update to: Adjust checks of ICHAR/IACHAR argument length #73972

Merged
merged 1 commit into from
Nov 30, 2023

Conversation

klausler
Copy link
Contributor

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

When applying ICHAR/IACHAR to a character constant with length
greater than one, resize the character constant to its first
character.
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels Nov 30, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Nov 30, 2023

@llvm/pr-subscribers-flang-semantics

Author: Peter Klausler (klausler)

Changes

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


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

1 Files Affected:

  • (modified) flang/lib/Evaluate/fold-integer.cpp (+4-2)
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
             },

@klausler klausler merged commit 26f2f93 into llvm:main Nov 30, 2023
4 of 5 checks passed
@klausler klausler deleted the bug1432a branch November 30, 2023 19: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.

None yet

2 participants