[flang-commits] [flang] [flang][cuda] Do not consider function result as host array (PR #164669)

via flang-commits flang-commits at lists.llvm.org
Wed Oct 22 10:35:27 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-semantics

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

<details>
<summary>Changes</summary>

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

``````````

</details>


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


More information about the flang-commits mailing list