Skip to content

Commit 96e0930

Browse files
authored
[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<>.
1 parent ca0c9bc commit 96e0930

File tree

1 file changed

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

1 file changed

+8
-0
lines changed

flang/include/flang/Evaluate/tools.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,14 @@ template <typename A> common::IfNoLvalue<Expr<ResultType<A>>, A> AsExpr(A &&x) {
130130
return Expr<ResultType<A>>{std::move(x)};
131131
}
132132

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

0 commit comments

Comments
 (0)