Skip to content

Conversation

@clementval
Copy link
Contributor

The function result in a device function is not a host array. Avoid triggering the error Host array 'res' cannot be present in device context for this.

@clementval clementval requested a review from wangzpgi October 22, 2025 17:34
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels Oct 22, 2025
@llvmbot
Copy link
Member

llvmbot commented Oct 22, 2025

@llvm/pr-subscribers-flang-semantics

Author: Valentin Clement (バレンタイン クレメン) (clementval)

Changes

The function result in a device function is not a host array. Avoid triggering the error Host array 'res' cannot be present in device context for this.


Full diff: https://github.com/llvm/llvm-project/pull/164669.diff

2 Files Affected:

  • (modified) flang/lib/Semantics/check-cuda.cpp (+3)
  • (modified) flang/test/Semantics/cuf09.cuf (+6)
diff --git a/flang/lib/Semantics/check-cuda.cpp b/flang/lib/Semantics/check-cuda.cpp
index 3d2db6a9c8aa9..caa9bdd28f1f4 100644
--- a/flang/lib/Semantics/check-cuda.cpp
+++ b/flang/lib/Semantics/check-cuda.cpp
@@ -131,6 +131,9 @@ struct FindHostArray
     return (*this)(x.base());
   }
   Result operator()(const Symbol &symbol) const {
+    if (symbol.IsFuncResult()) {
+      return nullptr;
+    }
     if (const auto *details{
             symbol.GetUltimate().detailsIf<semantics::ObjectEntityDetails>()}) {
       if (details->IsArray() &&
diff --git a/flang/test/Semantics/cuf09.cuf b/flang/test/Semantics/cuf09.cuf
index 9178b0a63adbe..df6568df9b480 100644
--- a/flang/test/Semantics/cuf09.cuf
+++ b/flang/test/Semantics/cuf09.cuf
@@ -36,6 +36,12 @@ module m
     if (i .le. N) a(i) = m(i)
   end subroutine
 
+  attributes(device) function devfct(r1, r2) result(res)
+    real(4), intent(in) :: r1(3), r2(3)
+    real(4) :: res(3)
+    res = r1 - r2 ! Do not error on function result
+  end function
+
   attributes(global) subroutine hostparameter(a)
     integer :: a(*)
     i = threadIdx%x

@clementval clementval enabled auto-merge (squash) October 22, 2025 17:51
@clementval clementval merged commit 6c8ad30 into llvm:main Oct 22, 2025
11 of 12 checks passed
dvbuka pushed a commit to dvbuka/llvm-project that referenced this pull request Oct 27, 2025
)

The function result in a device function is not a host array. Avoid
triggering the error `Host array 'res' cannot be present in device
context` for this.
Lukacma pushed a commit to Lukacma/llvm-project that referenced this pull request Oct 29, 2025
)

The function result in a device function is not a host array. Avoid
triggering the error `Host array 'res' cannot be present in device
context` for this.
aokblast pushed a commit to aokblast/llvm-project that referenced this pull request Oct 30, 2025
)

The function result in a device function is not a host array. Avoid
triggering the error `Host array 'res' cannot be present in device
context` for this.
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