[flang-commits] [PATCH] D122590: [flang] prevent undefined behavior in character MAXLOC folding

Jean Perier via Phabricator via flang-commits flang-commits at lists.llvm.org
Tue Mar 29 00:34:55 PDT 2022


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGec13942e71da: [flang] prevent undefined behavior in character MAXLOC folding (authored by jeanPerier).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D122590/new/

https://reviews.llvm.org/D122590

Files:
  flang/lib/Evaluate/fold-integer.cpp
  flang/test/Evaluate/fold-findloc.f90


Index: flang/test/Evaluate/fold-findloc.f90
===================================================================
--- flang/test/Evaluate/fold-findloc.f90
+++ flang/test/Evaluate/fold-findloc.f90
@@ -60,4 +60,10 @@
   logical, parameter :: test_xi3b = all(maxloc(ia3, back=.true.) == [0,0,0])
   logical, parameter :: test_xi3c = all(maxloc(ia3, dim=2) == reshape([0,0,0,0],shape=[2,2]))
   logical, parameter :: test_xi3d = all(maxloc(ia3, dim=2, back=.true.) == reshape([0,0,0,0],shape=[2,2]))
+
+  character(1), parameter :: a(4) = ['a', 'b', 'a', 'b']
+  logical, parameter :: test_char1 = all(maxloc(a).eq.[2])
+  logical, parameter :: test_char2 = all(minloc(a).eq.[1])
+  logical, parameter :: test_char3 = all(maxloc(a, back=.true.).eq.[4])
+  logical, parameter :: test_char4 = all(minloc(a, back=.true.).eq.[3])
 end module
Index: flang/lib/Evaluate/fold-integer.cpp
===================================================================
--- flang/lib/Evaluate/fold-integer.cpp
+++ flang/lib/Evaluate/fold-integer.cpp
@@ -331,14 +331,12 @@
       if constexpr (T::category == TypeCategory::Logical) {
         // array(at) .EQV. value?
         static_assert(WHICH == WhichLocation::Findloc);
-        cmp.emplace(
-            ConvertToType<LogicalResult>(Expr<T>{LogicalOperation<T::kind>{
-                LogicalOperator::Eqv, Expr<T>{Constant<T>{std::move(element)}},
-                Expr<T>{Constant<T>{*value}}}}));
+        cmp.emplace(ConvertToType<LogicalResult>(
+            Expr<T>{LogicalOperation<T::kind>{LogicalOperator::Eqv,
+                Expr<T>{Constant<T>{element}}, Expr<T>{Constant<T>{*value}}}}));
       } else { // compare array(at) to value
-        cmp.emplace(
-            PackageRelation(relation, Expr<T>{Constant<T>{std::move(element)}},
-                Expr<T>{Constant<T>{*value}}));
+        cmp.emplace(PackageRelation(relation, Expr<T>{Constant<T>{element}},
+            Expr<T>{Constant<T>{*value}}));
       }
       Expr<LogicalResult> folded{Fold(context_, std::move(*cmp))};
       result = GetScalarConstantValue<LogicalResult>(folded).value().IsTrue();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D122590.418808.patch
Type: text/x-patch
Size: 2109 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220329/48839569/attachment.bin>


More information about the flang-commits mailing list