[flang-commits] [flang] 96e0930 - [flang][Evaluate] Fix AsGenericExpr for Relational (#138455)

via flang-commits flang-commits at lists.llvm.org
Tue May 6 09:59:29 PDT 2025


Author: Krzysztof Parzyszek
Date: 2025-05-06T11:59:22-05:00
New Revision: 96e09302f9e6617b68b7dca17a5a0c866e147d4d

URL: https://github.com/llvm/llvm-project/commit/96e09302f9e6617b68b7dca17a5a0c866e147d4d
DIFF: https://github.com/llvm/llvm-project/commit/96e09302f9e6617b68b7dca17a5a0c866e147d4d.diff

LOG: [flang][Evaluate] Fix AsGenericExpr for Relational (#138455)

The variant in Expr<Type<TypeCategory::Logical, KIND>> only contains
Relational<SomeType>, not other, more specific Relational<T> types.

When calling AsGenericExpr for a value of type Relational<T>, the AsExpr
function will attempt to create Expr<> directly for Relational<T>, which
won't work for the above reason.

Implement an overload of AsExpr for Relational<T>, which will wrap the
Relational<T> in Relational<SomeType> before creating Expr<>.

Added: 
    

Modified: 
    flang/include/flang/Evaluate/tools.h

Removed: 
    


################################################################################
diff  --git a/flang/include/flang/Evaluate/tools.h b/flang/include/flang/Evaluate/tools.h
index 1414eaf14f7d6..5cdabb3056d8f 100644
--- a/flang/include/flang/Evaluate/tools.h
+++ b/flang/include/flang/Evaluate/tools.h
@@ -130,6 +130,14 @@ template <typename A> common::IfNoLvalue<Expr<ResultType<A>>, A> AsExpr(A &&x) {
   return Expr<ResultType<A>>{std::move(x)};
 }
 
+template <typename T, typename U = typename Relational<T>::Result>
+Expr<U> AsExpr(Relational<T> &&x) {
+  // The variant in Expr<Type<TypeCategory::Logical, KIND>> only contains
+  // Relational<SomeType>, not other Relational<T>s. Wrap the Relational<T>
+  // in Relational<SomeType> before creating Expr<>.
+  return Expr<U>(Relational<SomeType>{std::move(x)});
+}
+
 template <typename T> Expr<T> AsExpr(Expr<T> &&x) {
   static_assert(IsSpecificIntrinsicType<T>);
   return std::move(x);


        


More information about the flang-commits mailing list