From 053e565b483b94d72b183bfd991c39ce2c27af60 Mon Sep 17 00:00:00 2001 From: Krzysztof Parzyszek Date: Sun, 4 May 2025 10:13:47 -0500 Subject: [PATCH 1/2] [flang][Evaluate] Fix AsGenericExpr for Relational The variant in Expr> only contains Relational, not other, more specific Relational types. When calling AsGenericExpr for a value of type Relational, the AsExpr function will attempt to create Expr<> directly for Relational, which won't work for the above reason. Implement an overload of AsExpr for Relational, which will wrap the Relational in Relational before creating Expr<>. --- flang/include/flang/Evaluate/tools.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/flang/include/flang/Evaluate/tools.h b/flang/include/flang/Evaluate/tools.h index 1414eaf14f7d6..cd29872c1e0fd 100644 --- a/flang/include/flang/Evaluate/tools.h +++ b/flang/include/flang/Evaluate/tools.h @@ -125,11 +125,18 @@ template bool IsCoarray(const A &x) { return GetCorank(x) > 0; } // Generalizing packagers: these take operations and expressions of more // specific types and wrap them in Expr<> containers of more abstract types. - template common::IfNoLvalue>, A> AsExpr(A &&x) { return Expr>{std::move(x)}; } +template ::Result> +Expr AsExpr(Relational &&x) { + // The variant in Expr> only contains + // Relational, not other Relationals. Wrap the Relational + // in Relational before creating Expr<>. + return Expr(Relational{std::move(x)}); +} + template Expr AsExpr(Expr &&x) { static_assert(IsSpecificIntrinsicType); return std::move(x); From a9daa4c7e4df3b0f0ca79f0abe55fc4f124f50cd Mon Sep 17 00:00:00 2001 From: Krzysztof Parzyszek Date: Sun, 4 May 2025 11:14:49 -0500 Subject: [PATCH 2/2] Add deleted empty line back --- flang/include/flang/Evaluate/tools.h | 1 + 1 file changed, 1 insertion(+) diff --git a/flang/include/flang/Evaluate/tools.h b/flang/include/flang/Evaluate/tools.h index cd29872c1e0fd..5cdabb3056d8f 100644 --- a/flang/include/flang/Evaluate/tools.h +++ b/flang/include/flang/Evaluate/tools.h @@ -125,6 +125,7 @@ template bool IsCoarray(const A &x) { return GetCorank(x) > 0; } // Generalizing packagers: these take operations and expressions of more // specific types and wrap them in Expr<> containers of more abstract types. + template common::IfNoLvalue>, A> AsExpr(A &&x) { return Expr>{std::move(x)}; }