Skip to content

Commit 66028ef

Browse files
Split FindCommonBlock() into FindCB() and FindCommonBlockInScopes(). This resolves OpenMP regressions with COMMON. Still working on USE-association for COMMON blocks
1 parent 9e19979 commit 66028ef

File tree

3 files changed

+38
-10
lines changed

3 files changed

+38
-10
lines changed

flang/include/flang/Semantics/scope.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,21 @@ class Scope {
189189
mapType &commonBlocks() { return commonBlocks_; }
190190
const mapType &commonBlocks() const { return commonBlocks_; }
191191
Symbol &MakeCommonBlock(SourceName, SourceName location);
192+
193+
/// Find COMMON block in the current scope
194+
Symbol *FindCB(const SourceName &name) const {
195+
if (const auto it{commonBlocks_.find(name)}; it != commonBlocks_.end()) {
196+
return &*it->second;
197+
}
198+
return nullptr;
199+
}
200+
201+
/// Find COMMON block that is not USE-associated in the current scope
192202
Symbol *FindCommonBlock(const SourceName &) const;
193203

204+
/// Find COMMON block in current and surrounding scopes, follow USE associations
205+
Symbol *FindCommonBlockInScopes(const SourceName &) const;
206+
194207
/// Make a Symbol but don't add it to the scope.
195208
template <typename D>
196209
common::IfNoLvalue<Symbol &, D> MakeSymbol(

flang/lib/Semantics/resolve-directives.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1698,7 +1698,7 @@ Symbol *AccAttributeVisitor::ResolveAccCommonBlockName(
16981698
if (!name) {
16991699
return nullptr;
17001700
}
1701-
if (auto *cb{GetContext().scope.FindCommonBlock(name->source)}) {
1701+
if (auto *cb{GetContext().scope.FindCommonBlockInScopes(name->source)}) {
17021702
name->symbol = cb;
17031703
return cb;
17041704
}

flang/lib/Semantics/scope.cpp

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -154,18 +154,33 @@ Symbol &Scope::MakeCommonBlock(SourceName name, SourceName location) {
154154
return symbol;
155155
}
156156
}
157+
157158
Symbol *Scope::FindCommonBlock(const SourceName &name) const {
158-
if (const auto it{commonBlocks_.find(name)}; it != commonBlocks_.end()) {
159-
return &*it->second;
159+
if (auto *cb{FindCB(name)}) {
160+
// Ensure this COMMON block is not USE-associated
161+
if (cb->has<UseDetails>()) {
162+
cb = nullptr;
163+
}
164+
return cb;
165+
}
166+
return nullptr;
167+
}
168+
169+
Symbol *Scope::FindCommonBlockInScopes(const SourceName &name) const {
170+
if (auto *cb{FindCB(name)}) {
171+
return &cb->GetUltimate();
160172
} else if (IsSubmodule()) {
161-
const Scope *parent{
162-
symbol_ ? symbol_->get<ModuleDetails>().parent() : nullptr};
163-
return parent ? parent->FindCommonBlock(name) : nullptr;
164-
} else if (!IsTopLevel()) {
165-
return parent_ ? parent_->FindCommonBlock(name) : nullptr;
166-
} else {
167-
return nullptr;
173+
if (const Scope *parent{symbol_ ? symbol_->get<ModuleDetails>().parent() : nullptr}) {
174+
if (auto *cb{parent->FindCommonBlockInScopes(name)}) {
175+
return &cb->GetUltimate();
176+
}
177+
}
178+
} else if (!IsTopLevel() && parent_) {
179+
if (auto *cb{parent_->FindCommonBlockInScopes(name)}) {
180+
return &cb->GetUltimate();
181+
}
168182
}
183+
return nullptr;
169184
}
170185

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

0 commit comments

Comments
 (0)