[flang-commits] [PATCH] D157340: [flang] Fix folding of character array kind conversion
Peter Klausler via Phabricator via flang-commits
flang-commits at lists.llvm.org
Tue Aug 8 11:38:08 PDT 2023
This revision was automatically updated to reflect the committed changes.
Closed by commit rG351b42a2fd33: [flang] Fix folding of character array kind conversion (authored by klausler).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D157340/new/
https://reviews.llvm.org/D157340
Files:
flang/lib/Evaluate/fold-implementation.h
flang/test/Evaluate/folding31.f90
Index: flang/test/Evaluate/folding31.f90
===================================================================
--- /dev/null
+++ flang/test/Evaluate/folding31.f90
@@ -0,0 +1,6 @@
+! RUN: %python %S/test_folding.py %s %flang_fc1
+! Test folding of character array conversion.
+module m
+ character(*,4), parameter :: str4arr(1) = ['a']
+ logical, parameter :: test = str4arr(1) == 4_'a'
+end
Index: flang/lib/Evaluate/fold-implementation.h
===================================================================
--- flang/lib/Evaluate/fold-implementation.h
+++ flang/lib/Evaluate/fold-implementation.h
@@ -1349,6 +1349,7 @@
template <typename RESULT, typename OPERAND>
std::optional<Expr<RESULT>> MapOperation(FoldingContext &context,
std::function<Expr<RESULT>(Expr<OPERAND> &&)> &&f, const Shape &shape,
+ [[maybe_unused]] std::optional<Expr<SubscriptInteger>> &&length,
Expr<OPERAND> &&values) {
ArrayConstructor<RESULT> result{values};
if constexpr (common::HasMember<OPERAND, AllIntrinsicCategoryTypes>) {
@@ -1369,6 +1370,11 @@
result.Push(Fold(context, f(std::move(scalar))));
}
}
+ if constexpr (RESULT::category == TypeCategory::Character) {
+ if (length) {
+ result.set_LEN(std::move(*length));
+ }
+ }
return FromArrayConstructor(context, std::move(result), shape);
}
@@ -1506,9 +1512,9 @@
return FromArrayConstructor(context, std::move(result), shape);
}
-template <typename DERIVED, typename RESULT, typename LEFT, typename RIGHT>
+template <typename DERIVED, typename RESULT, typename... OPD>
std::optional<Expr<SubscriptInteger>> ComputeResultLength(
- Operation<DERIVED, RESULT, LEFT, RIGHT> &operation) {
+ Operation<DERIVED, RESULT, OPD...> &operation) {
if constexpr (RESULT::category == TypeCategory::Character) {
return Expr<RESULT>{operation.derived()}.LEN();
}
@@ -1529,7 +1535,8 @@
if (expr.Rank() > 0) {
if (std::optional<Shape> shape{GetShape(context, expr)}) {
if (auto values{AsFlatArrayConstructor(expr)}) {
- return MapOperation(context, std::move(f), *shape, std::move(*values));
+ return MapOperation(context, std::move(f), *shape,
+ ComputeResultLength(operation), std::move(*values));
}
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157340.548297.patch
Type: text/x-patch
Size: 2254 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20230808/6f8c6932/attachment-0001.bin>
More information about the flang-commits
mailing list