diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp index 3a1ccec1fdf4b..51e8b15e6adf0 100644 --- a/flang/lib/Semantics/resolve-names.cpp +++ b/flang/lib/Semantics/resolve-names.cpp @@ -8973,12 +8973,12 @@ void ResolveNamesVisitor::FinishSpecificationPart( if (NeedsExplicitType(symbol)) { ApplyImplicitRules(symbol); } - if (inDeviceSubprogram && IsDummy(symbol) && - symbol.has()) { - auto *dummy{symbol.detailsIf()}; - if (!dummy->cudaDataAttr() && !IsValue(symbol)) { + if (inDeviceSubprogram && symbol.has()) { + auto *object{symbol.detailsIf()}; + if (!object->cudaDataAttr() && !IsValue(symbol) && + (IsDummy(symbol) || object->IsArray())) { // Implicitly set device attribute if none is set in device context. - dummy->set_cudaDataAttr(common::CUDADataAttr::Device); + object->set_cudaDataAttr(common::CUDADataAttr::Device); } } if (IsDummy(symbol) && isImplicitNoneType() && diff --git a/flang/test/Semantics/cuf09.cuf b/flang/test/Semantics/cuf09.cuf index c551ecbff2cc0..e0ca814aec26a 100644 --- a/flang/test/Semantics/cuf09.cuf +++ b/flang/test/Semantics/cuf09.cuf @@ -22,6 +22,12 @@ module m !ERROR: Host array 'm' cannot be present in device context if (i .le. N) a(i) = m(i) end subroutine + + attributes(global) subroutine localarray() + integer :: a(10) + i = threadIdx%x + a(i) = i + end subroutine end program main