Skip to content

Commit e24c6a1

Browse files
committed
addressing comments
1 parent 2836b7b commit e24c6a1

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

flang/lib/Semantics/resolve-names.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2828,11 +2828,9 @@ Scope &ScopeHandler::NonDerivedTypeScope() {
28282828
return currScope_->IsDerivedType() ? currScope_->parent() : *currScope_;
28292829
}
28302830

2831-
static void SetImplicitCUDADevice(bool inDeviceSubprogram, Symbol &symbol) {
2832-
if (inDeviceSubprogram && symbol.has<ObjectEntityDetails>()) {
2833-
auto *object{symbol.detailsIf<ObjectEntityDetails>()};
2834-
if (!object->cudaDataAttr() && !IsValue(symbol) &&
2835-
!IsFunctionResult(symbol)) {
2831+
static void SetImplicitCUDADevice(Symbol &symbol) {
2832+
if (auto *object{symbol.detailsIf<ObjectEntityDetails>()}) {
2833+
if (!object->cudaDataAttr() && !IsValue(symbol) && !IsFunctionResult(symbol)) {
28362834
// Implicitly set device attribute if none is set in device context.
28372835
object->set_cudaDataAttr(common::CUDADataAttr::Device);
28382836
}
@@ -2879,9 +2877,9 @@ void ScopeHandler::PopScope() {
28792877
// assumed to be objects.
28802878
// TODO: Statement functions
28812879
bool inDeviceSubprogram{false};
2882-
Symbol *scopeSym{currScope().symbol()};
2880+
const Symbol *scopeSym{currScope().GetSymbol()};
28832881
if (currScope().kind() == Scope::Kind::BlockConstruct) {
2884-
scopeSym = currScope().parent().symbol();
2882+
scopeSym = GetProgramUnitContaining(currScope()).GetSymbol();
28852883
}
28862884
if (scopeSym) {
28872885
if (auto *details{scopeSym->detailsIf<SubprogramDetails>()}) {
@@ -2898,12 +2896,15 @@ void ScopeHandler::PopScope() {
28982896
}
28992897
for (auto &pair : currScope()) {
29002898
ConvertToObjectEntity(*pair.second);
2901-
if (currScope_->kind() == Scope::Kind::BlockConstruct) {
2902-
// Only look for specification in BlockConstruct. Other cases are done in
2903-
// ResolveSpecificationParts.
2904-
SetImplicitCUDADevice(inDeviceSubprogram, *pair.second);
2899+
}
2900+
2901+
// Apply CUDA device attributes if in a device subprogram
2902+
if (inDeviceSubprogram && currScope().kind() == Scope::Kind::BlockConstruct) {
2903+
for (auto &pair : currScope()) {
2904+
SetImplicitCUDADevice(*pair.second);
29052905
}
29062906
}
2907+
29072908
funcResultStack_.Pop();
29082909
// If popping back into a global scope, pop back to the top scope.
29092910
Scope *hermetic{context().currentHermeticModuleFileScope()};
@@ -10187,7 +10188,9 @@ void ResolveNamesVisitor::ResolveSpecificationParts(ProgramTree &node) {
1018710188
}
1018810189
ApplyImplicitRules(symbol);
1018910190
// Apply CUDA implicit attributes if needed.
10190-
SetImplicitCUDADevice(inDeviceSubprogram, symbol);
10191+
if (inDeviceSubprogram) {
10192+
SetImplicitCUDADevice(symbol);
10193+
}
1019110194
// Main program local objects usually don't have an implied SAVE attribute,
1019210195
// as one might think, but in the exceptional case of a derived type
1019310196
// local object that contains a coarray, we have to mark it as an

0 commit comments

Comments
 (0)