[flang-commits] [flang] 03095bd - [flang] Fix crash in semantics after PDT instantiation
Peter Klausler via flang-commits
flang-commits at lists.llvm.org
Tue May 24 11:06:22 PDT 2022
Author: Peter Klausler
Date: 2022-05-24T11:06:12-07:00
New Revision: 03095bd97b81b40d74762713b6ed72adb59df658
URL: https://github.com/llvm/llvm-project/commit/03095bd97b81b40d74762713b6ed72adb59df658
DIFF: https://github.com/llvm/llvm-project/commit/03095bd97b81b40d74762713b6ed72adb59df658.diff
LOG: [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
Added:
Modified:
flang/lib/Semantics/type.cpp
Removed:
################################################################################
diff --git a/flang/lib/Semantics/type.cpp b/flang/lib/Semantics/type.cpp
index f6888a7198e24..98ad4fd6d0361 100644
--- a/flang/lib/Semantics/type.cpp
+++ b/flang/lib/Semantics/type.cpp
@@ -373,8 +373,11 @@ void DerivedTypeSpec::Instantiate(Scope &containingScope) {
}
void InstantiateHelper::InstantiateComponents(const Scope &fromScope) {
- for (const auto &pair : fromScope) {
- InstantiateComponent(*pair.second);
+ // Instantiate symbols in declaration order; this ensures that
+ // parent components and type parameters of ancestor types exist
+ // by the time that they're needed.
+ for (SymbolRef ref : fromScope.GetSymbols()) {
+ InstantiateComponent(*ref);
}
ComputeOffsets(context(), scope_);
}
@@ -396,7 +399,7 @@ class ComponentInitResetHelper {
void Post(const parser::Name &name) {
if (name.symbol && name.symbol->has<TypeParamDetails>()) {
- name.symbol = scope_.FindSymbol(name.source);
+ name.symbol = scope_.FindComponent(name.source);
}
}
More information about the flang-commits
mailing list