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

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


Author: Valentin Clement (バレンタイン クレメン)
Date: 2025-10-22T17:55:11Z
New Revision: 6c8ad30a82a7ed240cbc3abc07c6759905fecd5b

URL: https://github.com/llvm/llvm-project/commit/6c8ad30a82a7ed240cbc3abc07c6759905fecd5b
DIFF: https://github.com/llvm/llvm-project/commit/6c8ad30a82a7ed240cbc3abc07c6759905fecd5b.diff

LOG: [flang][cuda] Do not consider function result as host array (#164669)

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.

Added: 
    

Modified: 
    flang/lib/Semantics/check-cuda.cpp
    flang/test/Semantics/cuf09.cuf

Removed: 
    


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


        


More information about the flang-commits mailing list