diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp index b576f59e8c7e5..aef2898919f3f 100644 --- a/flang/lib/Semantics/resolve-names.cpp +++ b/flang/lib/Semantics/resolve-names.cpp @@ -8953,6 +8953,18 @@ void ResolveNamesVisitor::FinishSpecificationPart( misparsedStmtFuncFound_ = false; funcResultStack().CompleteFunctionResultType(); CheckImports(); + bool inDeviceSubprogram = false; + if (auto *subp{currScope().symbol() + ? currScope().symbol()->detailsIf() + : nullptr}) { + if (auto attrs{subp->cudaSubprogramAttrs()}) { + if (*attrs != common::CUDASubprogramAttrs::Device || + *attrs != common::CUDASubprogramAttrs::Global || + *attrs != common::CUDASubprogramAttrs::Grid_Global) { + inDeviceSubprogram = true; + } + } + } for (auto &pair : currScope()) { auto &symbol{*pair.second}; if (inInterfaceBlock()) { @@ -8961,6 +8973,14 @@ void ResolveNamesVisitor::FinishSpecificationPart( if (NeedsExplicitType(symbol)) { ApplyImplicitRules(symbol); } + if (inDeviceSubprogram && IsDummy(symbol) && + symbol.has()) { + auto *dummy{symbol.detailsIf()}; + if (!dummy->cudaDataAttr()) { + // Implicitly set device attribute if none is set in device context. + dummy->set_cudaDataAttr(common::CUDADataAttr::Device); + } + } if (IsDummy(symbol) && isImplicitNoneType() && symbol.test(Symbol::Flag::Implicit) && !context().HasError(symbol)) { Say(symbol.name(), diff --git a/flang/test/Semantics/modfile55.cuf b/flang/test/Semantics/modfile55.cuf index cf01bdd5f58f6..6c0d152a382a8 100644 --- a/flang/test/Semantics/modfile55.cuf +++ b/flang/test/Semantics/modfile55.cuf @@ -29,6 +29,7 @@ end !contains !attributes(global) subroutine globsub(x,y,z) !real(4),value::x +!attributes(device) x !real(4)::y !attributes(device) y !real(4)::z