[flang-commits] [flang] [Flang] Check if two ArrayConstructor's are Equal (PR #121181)
via flang-commits
flang-commits at lists.llvm.org
Fri Jan 10 09:06:16 PST 2025
================
@@ -545,9 +545,51 @@ 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) {
+ using Expr = Fortran::evaluate::Expr<A>;
+ for (const auto &[xValue, yValue] : llvm::zip(x.values(), y.values())) {
+ bool checkValue = Fortran::common::visit(
+ common::visitors{
+ [&](const Expr &v, const Expr &w) { return isEqual(v, w); },
+ [&](const auto &, const auto &) {
+ llvm::report_fatal_error("isEqual is not handled yet for "
+ "the element type in ImpliedDo");
+ return false;
+ },
+ },
+ xValue.u, yValue.u);
+ if (!checkValue) {
+ return false;
+ }
+ }
+ return isEqual(x.lower(), y.lower()) && isEqual(x.upper(), y.upper()) &&
+ isEqual(x.stride(), y.stride());
+ }
+ template <typename A>
static bool isEqual(const Fortran::evaluate::ArrayConstructor<A> &x,
const Fortran::evaluate::ArrayConstructor<A> &y) {
- llvm::report_fatal_error("not implemented");
+ for (const auto &[xValue, yValue] : llvm::zip(x, y)) {
+ using Expr = Fortran::evaluate::Expr<A>;
+ using ImpliedDo = Fortran::evaluate::ImpliedDo<A>;
+ 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 auto &, const auto &) {
+ llvm::report_fatal_error("isEqual is not handled yet for "
+ "the element type in ImpliedDo");
+ return false;
+ },
+ },
+ xValue.u, yValue.u);
+ if (!checkElement) {
+ return false;
+ }
+ }
+ return x.GetType() == y.GetType();
----------------
jeanPerier wrote:
I think you need a special case for characters for the [length_ field ](https://github.com/llvm/llvm-project/blob/5d26a6d7590f13d21d78f7f0a443b92b04c80f98/flang/include/flang/Evaluate/expression.h#L497) that is not reflected in the `GetType()` (you can put that check under something like `if constexpr (A::category == Fortran::common::TypeCategory::Character)`)
https://github.com/llvm/llvm-project/pull/121181
More information about the flang-commits
mailing list