@@ -8970,18 +8970,6 @@ void ResolveNamesVisitor::FinishSpecificationPart(
8970
8970
misparsedStmtFuncFound_ = false ;
8971
8971
funcResultStack ().CompleteFunctionResultType ();
8972
8972
CheckImports ();
8973
- bool inDeviceSubprogram = false ;
8974
- if (auto *subp{currScope ().symbol ()
8975
- ? currScope ().symbol ()->detailsIf <SubprogramDetails>()
8976
- : nullptr }) {
8977
- if (auto attrs{subp->cudaSubprogramAttrs ()}) {
8978
- if (*attrs == common::CUDASubprogramAttrs::Device ||
8979
- *attrs == common::CUDASubprogramAttrs::Global ||
8980
- *attrs == common::CUDASubprogramAttrs::Grid_Global) {
8981
- inDeviceSubprogram = true ;
8982
- }
8983
- }
8984
- }
8985
8973
for (auto &pair : currScope ()) {
8986
8974
auto &symbol{*pair.second };
8987
8975
if (inInterfaceBlock ()) {
@@ -8990,14 +8978,6 @@ void ResolveNamesVisitor::FinishSpecificationPart(
8990
8978
if (NeedsExplicitType (symbol)) {
8991
8979
ApplyImplicitRules (symbol);
8992
8980
}
8993
- if (inDeviceSubprogram && symbol.has <ObjectEntityDetails>()) {
8994
- auto *object{symbol.detailsIf <ObjectEntityDetails>()};
8995
- if (!object->cudaDataAttr () && !IsValue (symbol) &&
8996
- (IsDummy (symbol) || object->IsArray ())) {
8997
- // Implicitly set device attribute if none is set in device context.
8998
- object->set_cudaDataAttr (common::CUDADataAttr::Device);
8999
- }
9000
- }
9001
8981
if (IsDummy (symbol) && isImplicitNoneType () &&
9002
8982
symbol.test (Symbol::Flag::Implicit) && !context ().HasError (symbol)) {
9003
8983
Say (symbol.name (),
@@ -9522,6 +9502,7 @@ void ResolveNamesVisitor::ResolveSpecificationParts(ProgramTree &node) {
9522
9502
},
9523
9503
node.stmt ());
9524
9504
Walk (node.spec ());
9505
+ bool inDeviceSubprogram = false ;
9525
9506
// If this is a function, convert result to an object. This is to prevent the
9526
9507
// result from being converted later to a function symbol if it is called
9527
9508
// inside the function.
@@ -9535,6 +9516,15 @@ void ResolveNamesVisitor::ResolveSpecificationParts(ProgramTree &node) {
9535
9516
if (details->isFunction ()) {
9536
9517
ConvertToObjectEntity (const_cast <Symbol &>(details->result ()));
9537
9518
}
9519
+ // Check the current procedure is a device procedure to apply implicit
9520
+ // attribute at the end.
9521
+ if (auto attrs{details->cudaSubprogramAttrs ()}) {
9522
+ if (*attrs == common::CUDASubprogramAttrs::Device ||
9523
+ *attrs == common::CUDASubprogramAttrs::Global ||
9524
+ *attrs == common::CUDASubprogramAttrs::Grid_Global) {
9525
+ inDeviceSubprogram = true ;
9526
+ }
9527
+ }
9538
9528
}
9539
9529
}
9540
9530
if (node.IsModule ()) {
@@ -9561,6 +9551,15 @@ void ResolveNamesVisitor::ResolveSpecificationParts(ProgramTree &node) {
9561
9551
symbol.GetType () ? Symbol::Flag::Function : Symbol::Flag::Subroutine);
9562
9552
}
9563
9553
ApplyImplicitRules (symbol);
9554
+ // Apply CUDA implicit attributes if needed.
9555
+ if (inDeviceSubprogram && symbol.has <ObjectEntityDetails>()) {
9556
+ auto *object{symbol.detailsIf <ObjectEntityDetails>()};
9557
+ if (!object->cudaDataAttr () && !IsValue (symbol) &&
9558
+ (IsDummy (symbol) || object->IsArray ())) {
9559
+ // Implicitly set device attribute if none is set in device context.
9560
+ object->set_cudaDataAttr (common::CUDADataAttr::Device);
9561
+ }
9562
+ }
9564
9563
}
9565
9564
}
9566
9565
0 commit comments