[flang-commits] [flang] [flang][cuda] Do not consider function result as host array (PR #164669)
Valentin Clement バレンタイン クレメン via flang-commits
flang-commits at lists.llvm.org
Wed Oct 22 10:34:39 PDT 2025
https://github.com/clementval created https://github.com/llvm/llvm-project/pull/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.
>From 856deb7287234fdc8206627327c85611fbcef1d0 Mon Sep 17 00:00:00 2001
From: Valentin Clement <clementval at gmail.com>
Date: Wed, 22 Oct 2025 10:33:12 -0700
Subject: [PATCH] [flang][cuda] Do not consider function result as host array
---
flang/lib/Semantics/check-cuda.cpp | 3 +++
flang/test/Semantics/cuf09.cuf | 6 ++++++
2 files changed, 9 insertions(+)
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