Skip to content

Commit ff637dd

Browse files
Updated Scope::FindCommonBlock() to be similar to Scope::FindSymbol(). (Currently the code doesn't fix ACC COMMON problem.)
1 parent 430660f commit ff637dd

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

flang/lib/Semantics/resolve-directives.cpp

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1698,21 +1698,10 @@ Symbol *AccAttributeVisitor::ResolveAccCommonBlockName(
16981698
if (!name) {
16991699
return nullptr;
17001700
}
1701-
// Check the local and surrounding scopes first
1702-
if (auto *cb{GetProgramUnitOrBlockConstructContaining(GetContext().scope)
1703-
.FindCommonBlock(name->source)}) {
1701+
if (auto *cb{GetContext().scope.FindCommonBlock(name->source)}) {
17041702
name->symbol = cb;
17051703
return cb;
17061704
}
1707-
// Look for COMMON block in the modules
1708-
for (const Scope &childScope : context_.globalScope().children()) {
1709-
if (childScope.kind() == Scope::Kind::Module) {
1710-
if (auto *cb{childScope.FindCommonBlock(name->source)}) {
1711-
name->symbol = cb;
1712-
return cb;
1713-
}
1714-
}
1715-
}
17161705
return nullptr;
17171706
}
17181707

flang/lib/Semantics/scope.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,16 @@ Symbol &Scope::MakeCommonBlock(SourceName name, SourceName location) {
155155
}
156156
}
157157
Symbol *Scope::FindCommonBlock(const SourceName &name) const {
158-
const auto it{commonBlocks_.find(name)};
159-
return it != commonBlocks_.end() ? &*it->second : nullptr;
158+
if (const auto it{commonBlocks_.find(name)}; it != commonBlocks_.end()) {
159+
return &*it->second;
160+
} else if (IsSubmodule()) {
161+
const Scope *parent{symbol_ ? symbol_->get<ModuleDetails>().parent() : nullptr};
162+
return parent ? parent->FindCommonBlock(name) : nullptr;
163+
} else if (!IsTopLevel()) {
164+
return parent_ ? parent_->FindCommonBlock(name) : nullptr;
165+
} else {
166+
return nullptr;
167+
}
160168
}
161169

162170
Scope *Scope::FindSubmodule(const SourceName &name) const {

0 commit comments

Comments
 (0)