-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[flang][Evaluate] Fix AsGenericExpr for Relational #138455
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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<>.
@llvm/pr-subscribers-flang-semantics Author: Krzysztof Parzyszek (kparzysz) ChangesThe 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:
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);
|
The commit message reads |
The Windows pre-merge failure is some kind of a glitch: the builder gets shutdown for some reason while still building. The buildkite Windows tests pass. Edit: Nvm, the test has passed now. |
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<>.
The variant in Expr<Type<TypeCategory::Logical, KIND>> 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<>.