[flang-commits] [flang] [flang][Evaluate] Fix AsGenericExpr for Relational (PR #138455)
via flang-commits
flang-commits at lists.llvm.org
Sun May 4 09:00:12 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-semantics
Author: Krzysztof Parzyszek (kparzysz)
<details>
<summary>Changes</summary>
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<>.
---
Full diff: https://github.com/llvm/llvm-project/pull/138455.diff
1 Files Affected:
- (modified) flang/include/flang/Evaluate/tools.h (+8-1)
``````````diff
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 <typename A> 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 <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);
``````````
</details>
https://github.com/llvm/llvm-project/pull/138455
More information about the flang-commits
mailing list