Skip to content

Commit bbeafe4

Browse files
authored
[flang][cuda] Apply implict data attribute to local arrays (#120293)
Add the implicit data attribute to local arrays that don't have one. This simplifies the host array detection in semantic.
1 parent d7d0e74 commit bbeafe4

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

flang/lib/Semantics/resolve-names.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8973,12 +8973,12 @@ void ResolveNamesVisitor::FinishSpecificationPart(
89738973
if (NeedsExplicitType(symbol)) {
89748974
ApplyImplicitRules(symbol);
89758975
}
8976-
if (inDeviceSubprogram && IsDummy(symbol) &&
8977-
symbol.has<ObjectEntityDetails>()) {
8978-
auto *dummy{symbol.detailsIf<ObjectEntityDetails>()};
8979-
if (!dummy->cudaDataAttr() && !IsValue(symbol)) {
8976+
if (inDeviceSubprogram && symbol.has<ObjectEntityDetails>()) {
8977+
auto *object{symbol.detailsIf<ObjectEntityDetails>()};
8978+
if (!object->cudaDataAttr() && !IsValue(symbol) &&
8979+
(IsDummy(symbol) || object->IsArray())) {
89808980
// Implicitly set device attribute if none is set in device context.
8981-
dummy->set_cudaDataAttr(common::CUDADataAttr::Device);
8981+
object->set_cudaDataAttr(common::CUDADataAttr::Device);
89828982
}
89838983
}
89848984
if (IsDummy(symbol) && isImplicitNoneType() &&

flang/test/Semantics/cuf09.cuf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ module m
2222
!ERROR: Host array 'm' cannot be present in device context
2323
if (i .le. N) a(i) = m(i)
2424
end subroutine
25+
26+
attributes(global) subroutine localarray()
27+
integer :: a(10)
28+
i = threadIdx%x
29+
a(i) = i
30+
end subroutine
2531
end
2632

2733
program main

0 commit comments

Comments
 (0)