Skip to content

Commit 73f21db

Browse files
committed
[flang] Fix: use right symbol for parent component
When constructing the representation for a component reference to an inherited component, expression semantics make the parent component references explicit in the DataRef; e.g., base%component becomes base%parent%grandparent%component if component was inheritance-associated through two levels. But expression semantics was inserting references to the symbol table entries for the intermediate types, not the symbols for the parent components in the extended types. (We didn't notice the distinction until recently because both symbols have the same name; this only affects lowering.) Find and use the right symbols. Differential Revision: https://reviews.llvm.org/D118746
1 parent 0b5fb7c commit 73f21db

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

flang/include/flang/Semantics/symbol.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,11 @@ class Symbol {
665665
// for a parameterized derived type instantiation with the instance's scope.
666666
const DerivedTypeSpec *GetParentTypeSpec(const Scope * = nullptr) const;
667667

668+
// If a derived type's symbol refers to an extended derived type,
669+
// return the parent component's symbol. The scope of the derived type
670+
// can be overridden.
671+
const Symbol *GetParentComponent(const Scope * = nullptr) const;
672+
668673
SemanticsContext &GetSemanticsContext() const;
669674
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
670675
LLVM_DUMP_METHOD void dump() const;
@@ -686,11 +691,6 @@ class Symbol {
686691
friend llvm::raw_ostream &DumpForUnparse(
687692
llvm::raw_ostream &, const Symbol &, bool);
688693

689-
// If a derived type's symbol refers to an extended derived type,
690-
// return the parent component's symbol. The scope of the derived type
691-
// can be overridden.
692-
const Symbol *GetParentComponent(const Scope * = nullptr) const;
693-
694694
template <std::size_t> friend class Symbols;
695695
template <class, std::size_t> friend class std::array;
696696
};

flang/lib/Semantics/expression.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -987,11 +987,20 @@ std::optional<Component> ExpressionAnalyzer::CreateComponent(
987987
if (&component.owner() == &scope) {
988988
return Component{std::move(base), component};
989989
}
990-
if (const semantics::Scope * parentScope{scope.GetDerivedTypeParent()}) {
991-
if (const Symbol * parentComponent{parentScope->GetSymbol()}) {
992-
return CreateComponent(
993-
DataRef{Component{std::move(base), *parentComponent}}, component,
994-
*parentScope);
990+
if (const Symbol * typeSymbol{scope.GetSymbol()}) {
991+
if (const Symbol *
992+
parentComponent{typeSymbol->GetParentComponent(&scope)}) {
993+
if (const auto *object{
994+
parentComponent->detailsIf<semantics::ObjectEntityDetails>()}) {
995+
if (const auto *parentType{object->type()}) {
996+
if (const semantics::Scope *
997+
parentScope{parentType->derivedTypeSpec().scope()}) {
998+
return CreateComponent(
999+
DataRef{Component{std::move(base), *parentComponent}},
1000+
component, *parentScope);
1001+
}
1002+
}
1003+
}
9951004
}
9961005
}
9971006
return std::nullopt;

0 commit comments

Comments
 (0)