[flang-commits] [PATCH] D126147: [flang] Fix crash in semantics after PDT instantiation
Peter Klausler via Phabricator via flang-commits
flang-commits at lists.llvm.org
Sat May 21 22:13:04 PDT 2022
klausler created this revision.
klausler added a reviewer: vdonaldson.
klausler added a project: Flang.
Herald added a subscriber: jdoerfert.
Herald added a project: All.
klausler requested review of this revision.
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.
https://reviews.llvm.org/D126147
Files:
flang/lib/Semantics/type.cpp
Index: flang/lib/Semantics/type.cpp
===================================================================
--- flang/lib/Semantics/type.cpp
+++ flang/lib/Semantics/type.cpp
@@ -373,8 +373,11 @@
}
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 @@
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);
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D126147.431204.patch
Type: text/x-patch
Size: 902 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220522/093ace13/attachment.bin>
More information about the flang-commits
mailing list