Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[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

Merged
merged 2 commits into from
May 6, 2025

Conversation

kparzysz
Copy link
Contributor

@kparzysz kparzysz commented May 4, 2025

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<>.

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<>.
@kparzysz kparzysz requested a review from klausler May 4, 2025 15:59
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels May 4, 2025
@llvmbot
Copy link
Member

llvmbot commented May 4, 2025

@llvm/pr-subscribers-flang-semantics

Author: Krzysztof Parzyszek (kparzysz)

Changes

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 --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);

@kparzysz
Copy link
Contributor Author

kparzysz commented May 4, 2025

The commit message reads ... only contains Relational<SomeType>, not other, more specific Relational<T> types. The rendering in the top comment doesn't show some of the the <...>s for some reason.

@kparzysz
Copy link
Contributor Author

kparzysz commented May 4, 2025

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.

@kparzysz kparzysz merged commit 96e0930 into llvm:main May 6, 2025
11 checks passed
@kparzysz kparzysz deleted the users/kparzysz/asexpr-relational branch May 6, 2025 16:59
GeorgeARM pushed a commit to GeorgeARM/llvm-project that referenced this pull request May 7, 2025
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<>.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:semantics flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants