Skip to content

Commit eac75b7

Browse files
Handle the case of redeclared COMMON block
1 parent 41336f1 commit eac75b7

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

flang/include/flang/Semantics/symbol.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,7 @@ class Symbol {
884884
const Details &details() const { return details_; }
885885
// Assign the details of the symbol from one of the variants.
886886
// Only allowed in certain cases.
887-
void set_details(Details &&);
887+
void set_details(Details &&, bool force = false);
888888

889889
// Can the details of this symbol be replaced with the given details?
890890
bool CanReplaceDetails(const Details &details) const;

flang/lib/Semantics/scope.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,21 @@ void Scope::add_crayPointer(const SourceName &name, Symbol &pointer) {
145145

146146
Symbol &Scope::MakeCommonBlock(SourceName name, SourceName location) {
147147
if (auto *cb{FindCB(name)}) {
148+
if (cb->has<UseDetails>()) {
149+
// COMMON blocks could be re-declared. Example:
150+
// module test
151+
// integer :: a
152+
// common /blk/ a
153+
// end module test
154+
// program main
155+
// use test ! Initially get /blk/ with UseDetails
156+
// integer :: a1
157+
// common /blk/ a1 ! Update with CommonBlockDetails
158+
// end program main
159+
// Reset details with real COMMON block details.
160+
cb->set_details(CommonBlockDetails{name.empty() ? location : name},
161+
/*force*/true);
162+
}
148163
return *cb;
149164
} else {
150165
Symbol &symbol{MakeSymbol(

flang/lib/Semantics/symbol.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,10 @@ std::string DetailsToString(const Details &details) {
317317

318318
std::string Symbol::GetDetailsName() const { return DetailsToString(details_); }
319319

320-
void Symbol::set_details(Details &&details) {
321-
CHECK(CanReplaceDetails(details));
320+
void Symbol::set_details(Details &&details, bool force) {
321+
if (!force) {
322+
CHECK(CanReplaceDetails(details));
323+
}
322324
details_ = std::move(details);
323325
}
324326

0 commit comments

Comments
 (0)