Skip to content

Commit 053e565

Browse files
committed
[flang][Evaluate] Fix AsGenericExpr for Relational
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<>.
1 parent d144c13 commit 053e565

File tree

1 file changed

+8
-1
lines changed
  • flang/include/flang/Evaluate

1 file changed

+8
-1
lines changed

flang/include/flang/Evaluate/tools.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,18 @@ template <typename A> bool IsCoarray(const A &x) { return GetCorank(x) > 0; }
125125

126126
// Generalizing packagers: these take operations and expressions of more
127127
// specific types and wrap them in Expr<> containers of more abstract types.
128-
129128
template <typename A> common::IfNoLvalue<Expr<ResultType<A>>, A> AsExpr(A &&x) {
130129
return Expr<ResultType<A>>{std::move(x)};
131130
}
132131

132+
template <typename T, typename U = typename Relational<T>::Result>
133+
Expr<U> AsExpr(Relational<T> &&x) {
134+
// The variant in Expr<Type<TypeCategory::Logical, KIND>> only contains
135+
// Relational<SomeType>, not other Relational<T>s. Wrap the Relational<T>
136+
// in Relational<SomeType> before creating Expr<>.
137+
return Expr<U>(Relational<SomeType>{std::move(x)});
138+
}
139+
133140
template <typename T> Expr<T> AsExpr(Expr<T> &&x) {
134141
static_assert(IsSpecificIntrinsicType<T>);
135142
return std::move(x);

0 commit comments

Comments
 (0)