Skip to content

Commit fc6beb7

Browse files
[AddOrUpdateCommonBlockUse] Implemented selection of largest COMMON block in case of uses from multiple modules, except that it doesn't work: COMMON block sizes are computed after the name resolution
1 parent abd2f40 commit fc6beb7

File tree

4 files changed

+9
-30
lines changed

4 files changed

+9
-30
lines changed

flang/include/flang/Semantics/scope.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ class Scope {
194194
const mapType &crayPointers() const { return crayPointers_; }
195195
void add_crayPointer(const SourceName &, Symbol &);
196196
Symbol &MakeCommonBlock(SourceName, SourceName location);
197-
bool AddOrUpdateCommonBlockUse(const SourceName &name, Attrs attrs, Symbol& cbUltimate);
197+
bool AddCommonBlockUse(const SourceName &name, Attrs attrs, Symbol& cbUltimate);
198198

199199
// Find COMMON block that is declared in the current scope
200200
Symbol *FindCommonBlock(const SourceName &name) const {

flang/lib/Semantics/resolve-names.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3631,14 +3631,14 @@ void ModuleVisitor::Post(const parser::UseStmt &x) {
36313631
// their USE association to the current scope's USE-associated COMMON blocks.
36323632
for (const auto &[name, symbol] : useModuleScope_->commonBlocks()) {
36333633
if (!currScope().FindCommonBlockInVisibleScopes(name)) {
3634-
currScope().AddOrUpdateCommonBlockUse(name, symbol->attrs(), symbol->GetUltimate());
3634+
currScope().AddCommonBlockUse(name, symbol->attrs(), symbol->GetUltimate());
36353635
}
36363636
}
36373637
// Go through the list of USE-associated COMMON block symbols in the module
36383638
// scope and add USE associations to their ultimate symbols to the current
36393639
// scope's USE-associated COMMON blocks.
36403640
for (const auto &[name, symbol] : useModuleScope_->commonBlockUses()) {
3641-
currScope().AddOrUpdateCommonBlockUse(name, symbol->attrs(), symbol->GetUltimate());
3641+
currScope().AddCommonBlockUse(name, symbol->attrs(), symbol->GetUltimate());
36423642
}
36433643
useModuleScope_ = nullptr;
36443644
}

flang/lib/Semantics/scope.cpp

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -183,24 +183,12 @@ Scope *Scope::FindSubmodule(const SourceName &name) const {
183183
}
184184
}
185185

186-
bool Scope::AddOrUpdateCommonBlockUse(const SourceName &name, Attrs attrs, Symbol& cbUltimate) {
186+
bool Scope::AddCommonBlockUse(const SourceName &name, Attrs attrs, Symbol& cbUltimate) {
187187
CHECK(cbUltimate.has<CommonBlockDetails>());
188-
if (Symbol *cb{FindCommonBlockUse(name)}) {
189-
// We already stored UseDetails from the previous encounter with the
190-
// same named COMMON block (perhaps it came from a different module).
191-
// Ensure that we store USE association to the largest COMMON block,
192-
// which is presumably is better defined.
193-
Symbol &cbExistingUltimate{cb->GetUltimate()};
194-
if (cbExistingUltimate.size() < cbUltimate.size()) {
195-
cb->set_details(UseDetails{name, cbUltimate});
196-
}
197-
return true;
198-
} else {
199-
// Make a symbol, but don't add it to the Scope, since it needs to
200-
// be added to the USE-associated COMMON blocks
201-
Symbol &useCB{MakeSymbol(name, attrs, UseDetails{name, cbUltimate})};
202-
return commonBlockUses_.emplace(name, useCB).second;
203-
}
188+
// Make a symbol, but don't add it to the Scope, since it needs to
189+
// be added to the USE-associated COMMON blocks
190+
Symbol &useCB{MakeSymbol(name, attrs, UseDetails{name, cbUltimate})};
191+
return commonBlockUses_.emplace(name, useCB).second;
204192
}
205193

206194
bool Scope::AddSubmodule(const SourceName &name, Scope &submodule) {

flang/lib/Semantics/symbol.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -373,16 +373,7 @@ bool Symbol::CanReplaceDetails(const Details &details) const {
373373
},
374374
[&](const UseDetails &x) {
375375
const auto *use{this->detailsIf<UseDetails>()};
376-
if (!use) {
377-
return false;
378-
} else if (use->symbol().detailsIf<CommonBlockDetails>() &&
379-
x.symbol().detailsIf<CommonBlockDetails>()) {
380-
// Allow to replace UseDetails, if they both refer to COMMON
381-
// symbol with the same name.
382-
return use->symbol().name() == x.symbol().name();
383-
} else {
384-
return use->symbol() == x.symbol();
385-
}
376+
return use && use->symbol() == x.symbol();
386377
},
387378
[&](const HostAssocDetails &) { return has<HostAssocDetails>(); },
388379
[&](const UserReductionDetails &) {

0 commit comments

Comments
 (0)