Skip to content

Commit 03095bd

Browse files
committed
[flang] Fix crash in semantics after PDT instantiation
The code in semantics that reinitializes symbol table pointers in the parse tree of a parameterized derived type prior to a new instantiation of the type was processing the symbols of the derived type instantiation scope in arbitrary address order, which could fail if a reference to a type parameter inherited from an ancestor type was processed prior to the parent component sequence. Fix by instantiating components of PDT instantiations in declaration order. Differential Revision: https://reviews.llvm.org/D126147
1 parent 1e1f60c commit 03095bd

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

flang/lib/Semantics/type.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,8 +373,11 @@ void DerivedTypeSpec::Instantiate(Scope &containingScope) {
373373
}
374374

375375
void InstantiateHelper::InstantiateComponents(const Scope &fromScope) {
376-
for (const auto &pair : fromScope) {
377-
InstantiateComponent(*pair.second);
376+
// Instantiate symbols in declaration order; this ensures that
377+
// parent components and type parameters of ancestor types exist
378+
// by the time that they're needed.
379+
for (SymbolRef ref : fromScope.GetSymbols()) {
380+
InstantiateComponent(*ref);
378381
}
379382
ComputeOffsets(context(), scope_);
380383
}
@@ -396,7 +399,7 @@ class ComponentInitResetHelper {
396399

397400
void Post(const parser::Name &name) {
398401
if (name.symbol && name.symbol->has<TypeParamDetails>()) {
399-
name.symbol = scope_.FindSymbol(name.source);
402+
name.symbol = scope_.FindComponent(name.source);
400403
}
401404
}
402405

0 commit comments

Comments
 (0)