aboutsummaryrefslogtreecommitdiff
path: root/flang/lib/Evaluate/intrinsics.cpp
diff options
context:
space:
mode:
authorjeanPerier <jperier@nvidia.com>2023-09-11 12:52:11 +0200
committerGitHub <noreply@github.com>2023-09-11 12:52:11 +0200
commit8b13775d6a7c2b2f070fd32d320676ed5b19cbb2 (patch)
tree5776512cbd2e2ccbec1e2dcd73a3d9b14b52ee04 /flang/lib/Evaluate/intrinsics.cpp
parent6942c64e8128e4ccd891b813d0240f574f80f59e (diff)
downloadllvm-8b13775d6a7c2b2f070fd32d320676ed5b19cbb2.zip
llvm-8b13775d6a7c2b2f070fd32d320676ed5b19cbb2.tar.gz
llvm-8b13775d6a7c2b2f070fd32d320676ed5b19cbb2.tar.bz2
[flang] Improve length information in character transformational (#65771)
Intrinsic resolution currently does not resolve constant length information for character transformational (with "sameChar") where the argument has constant length but is not a variable or a constant expression. It is not required to fold those expressions (only inquiry on constant expression or variable with constant length is required to be a constant expression). But constant length information for character is valuable for lowering, so I think this is a nice and easy to have.
Diffstat (limited to 'flang/lib/Evaluate/intrinsics.cpp')
-rw-r--r--flang/lib/Evaluate/intrinsics.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/flang/lib/Evaluate/intrinsics.cpp b/flang/lib/Evaluate/intrinsics.cpp
index fd549dd..030e5b2 100644
--- a/flang/lib/Evaluate/intrinsics.cpp
+++ b/flang/lib/Evaluate/intrinsics.cpp
@@ -2093,7 +2093,15 @@ std::optional<SpecificCall> IntrinsicInterface::Match(
CHECK(sameArg);
if (std::optional<DynamicType> aType{sameArg->GetType()}) {
if (result.categorySet.test(aType->category())) {
- resultType = *aType;
+ if (const auto *sameChar{UnwrapExpr<Expr<SomeCharacter>>(*sameArg)}) {
+ if (auto len{ToInt64(Fold(context, sameChar->LEN()))}) {
+ resultType = DynamicType{aType->kind(), *len};
+ } else {
+ resultType = *aType;
+ }
+ } else {
+ resultType = *aType;
+ }
} else {
resultType = DynamicType{*category, aType->kind()};
}