@@ -1131,7 +1131,8 @@ class DeclarationVisitor : public ArraySpecVisitor,
1131
1131
bool OkToAddComponent (const parser::Name &, const Symbol * = nullptr );
1132
1132
ParamValue GetParamValue (
1133
1133
const parser::TypeParamValue &, common::TypeParamAttr attr);
1134
- void CheckCommonBlockDerivedType (const SourceName &, const Symbol &);
1134
+ void CheckCommonBlockDerivedType (
1135
+ const SourceName &, const Symbol &, UnorderedSymbolSet &);
1135
1136
Attrs HandleSaveName (const SourceName &, Attrs);
1136
1137
void AddSaveName (std::set<SourceName> &, const SourceName &);
1137
1138
bool HandleUnrestrictedSpecificIntrinsicFunction (const parser::Name &);
@@ -6096,7 +6097,8 @@ void DeclarationVisitor::CheckCommonBlocks() {
6096
6097
" Derived type '%s' in COMMON block must have the BIND or"
6097
6098
" SEQUENCE attribute" _err_en_US);
6098
6099
}
6099
- CheckCommonBlockDerivedType (name, typeSymbol);
6100
+ UnorderedSymbolSet typeSet;
6101
+ CheckCommonBlockDerivedType (name, typeSymbol, typeSet);
6100
6102
}
6101
6103
}
6102
6104
}
@@ -6120,8 +6122,12 @@ bool DeclarationVisitor::NameIsKnownOrIntrinsic(const parser::Name &name) {
6120
6122
}
6121
6123
6122
6124
// Check if this derived type can be in a COMMON block.
6123
- void DeclarationVisitor::CheckCommonBlockDerivedType (
6124
- const SourceName &name, const Symbol &typeSymbol) {
6125
+ void DeclarationVisitor::CheckCommonBlockDerivedType (const SourceName &name,
6126
+ const Symbol &typeSymbol, UnorderedSymbolSet &typeSet) {
6127
+ if (auto iter{typeSet.find (SymbolRef{typeSymbol})}; iter != typeSet.end ()) {
6128
+ return ;
6129
+ }
6130
+ typeSet.emplace (typeSymbol);
6125
6131
if (const auto *scope{typeSymbol.scope ()}) {
6126
6132
for (const auto &pair : *scope) {
6127
6133
const Symbol &component{*pair.second };
@@ -6144,13 +6150,7 @@ void DeclarationVisitor::CheckCommonBlockDerivedType(
6144
6150
if (const auto *type{details->type ()}) {
6145
6151
if (const auto *derived{type->AsDerived ()}) {
6146
6152
const Symbol &derivedTypeSymbol{derived->typeSymbol ()};
6147
- // Don't call this member function recursively if the derived type
6148
- // symbol is the same symbol that is already being processed.
6149
- // This can happen when a component is a pointer of the same type
6150
- // as its parent component, for instance.
6151
- if (derivedTypeSymbol != typeSymbol) {
6152
- CheckCommonBlockDerivedType (name, derivedTypeSymbol);
6153
- }
6153
+ CheckCommonBlockDerivedType (name, derivedTypeSymbol, typeSet);
6154
6154
}
6155
6155
}
6156
6156
}
0 commit comments