Skip to content

Commit 48a853b

Browse files
clementvaldvbuka
authored andcommitted
[flang][cuda] Do not consider function result as host array (llvm#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.
1 parent b7990f6 commit 48a853b

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

flang/lib/Semantics/check-cuda.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ struct FindHostArray
131131
return (*this)(x.base());
132132
}
133133
Result operator()(const Symbol &symbol) const {
134+
if (symbol.IsFuncResult()) {
135+
return nullptr;
136+
}
134137
if (const auto *details{
135138
symbol.GetUltimate().detailsIf<semantics::ObjectEntityDetails>()}) {
136139
if (details->IsArray() &&

flang/test/Semantics/cuf09.cuf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ module m
3636
if (i .le. N) a(i) = m(i)
3737
end subroutine
3838

39+
attributes(device) function devfct(r1, r2) result(res)
40+
real(4), intent(in) :: r1(3), r2(3)
41+
real(4) :: res(3)
42+
res = r1 - r2 ! Do not error on function result
43+
end function
44+
3945
attributes(global) subroutine hostparameter(a)
4046
integer :: a(*)
4147
i = threadIdx%x

0 commit comments

Comments
 (0)