[flang-commits] [flang] [Flang] Check if two ArrayConstructor's are Equal (PR #121181)

Thirumalai Shaktivel via flang-commits flang-commits at lists.llvm.org
Mon Jan 27 00:51:32 PST 2025


================
@@ -545,9 +545,43 @@ class IsEqualEvaluateExpr {
     return isEqual(x.proc(), y.proc()) && isEqual(x.arguments(), y.arguments());
   }
   template <typename A>
+  static bool isEqual(const Fortran::evaluate::ImpliedDo<A> &x,
+                      const Fortran::evaluate::ImpliedDo<A> &y) {
+    return isEqual(x.values(), y.values()) && isEqual(x.lower(), y.lower()) &&
+           isEqual(x.upper(), y.upper()) && isEqual(x.stride(), y.stride());
+  }
+  template <typename A>
+  static bool isEqual(const Fortran::evaluate::ArrayConstructorValues<A> &x,
+                      const Fortran::evaluate::ArrayConstructorValues<A> &y) {
+    using Expr = Fortran::evaluate::Expr<A>;
+    using ImpliedDo = Fortran::evaluate::ImpliedDo<A>;
+    for (const auto &[xValue, yValue] : llvm::zip(x, y)) {
+      bool checkElement = Fortran::common::visit(
+          common::visitors{
+              [&](const Expr &v, const Expr &w) { return isEqual(v, w); },
+              [&](const ImpliedDo &v, const ImpliedDo &w) {
+                return isEqual(v, w);
+              },
+              [&](const Expr &, const ImpliedDo &) { return false; },
+              [&](const ImpliedDo &, const Expr &) { return false; },
+          },
+          xValue.u, yValue.u);
+      if (!checkElement) {
+        return false;
+      }
+    }
+    return true;
+  }
+  template <typename A>
   static bool isEqual(const Fortran::evaluate::ArrayConstructor<A> &x,
                       const Fortran::evaluate::ArrayConstructor<A> &y) {
-    llvm::report_fatal_error("not implemented");
+    bool checkCharacterType = true;
+    if constexpr (A::category == Fortran::common::TypeCategory::Character) {
+      checkCharacterType = x.LEN() == y.LEN();
----------------
Thirumalai-Shaktivel wrote:

I took the first approach and implemented it: 6442b335c2a5d2560b3a67aed6d87e36eeea88e5, please let me know if any other changes to be made

https://github.com/llvm/llvm-project/pull/121181


More information about the flang-commits mailing list