From d0708e6285b88510649722fe8e6832ee1d7abfb1 Mon Sep 17 00:00:00 2001 From: Peter Klausler <35819229+klausler@users.noreply.github.com> Date: Mon, 15 Jan 2024 11:37:46 -0800 Subject: [flang] Refine IMPORT processing in module file generation (#77133) Procedure interfaces emitted to module files are including IMPORT statements for some symbols that don't need to be imported (base types and procedure interfaces for components of imported derived types) and omitting others (procedure interfaces for bindings in locally-defined derived types that are material to the interface). --- flang/lib/Semantics/mod-file.cpp | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'flang/lib/Semantics/mod-file.cpp') diff --git a/flang/lib/Semantics/mod-file.cpp b/flang/lib/Semantics/mod-file.cpp index e871255..ffdc315 100644 --- a/flang/lib/Semantics/mod-file.cpp +++ b/flang/lib/Semantics/mod-file.cpp @@ -1464,6 +1464,9 @@ void SubprogramSymbolCollector::DoSymbol( DoType(details.type()); } }, + [this](const ProcBindingDetails &details) { + DoSymbol(details.symbol()); + }, [](const auto &) {}, }, symbol.details()); @@ -1489,17 +1492,21 @@ void SubprogramSymbolCollector::DoType(const DeclTypeSpec *type) { default: if (const DerivedTypeSpec * derived{type->AsDerived()}) { const auto &typeSymbol{derived->typeSymbol()}; - if (const DerivedTypeSpec * extends{typeSymbol.GetParentTypeSpec()}) { - DoSymbol(extends->name(), extends->typeSymbol()); - } for (const auto &pair : derived->parameters()) { DoParamValue(pair.second); } - for (const auto &pair : *typeSymbol.scope()) { - const Symbol &comp{*pair.second}; - DoSymbol(comp); + // The components of the type (including its parent component, if + // any) matter to IMPORT symbol collection only for derived types + // defined in the subprogram. + if (typeSymbol.owner() == scope_) { + if (const DerivedTypeSpec * extends{typeSymbol.GetParentTypeSpec()}) { + DoSymbol(extends->name(), extends->typeSymbol()); + } + for (const auto &pair : *typeSymbol.scope()) { + DoSymbol(*pair.second); + } } - DoSymbol(derived->name(), derived->typeSymbol()); + DoSymbol(derived->name(), typeSymbol); } } } @@ -1531,8 +1538,8 @@ bool SubprogramSymbolCollector::NeedImport( // detect import from ancestor of use-associated symbol return found->has() && found->owner() != scope_; } else { - // "found" can be null in the case of a use-associated derived type's parent - // type + // "found" can be null in the case of a use-associated derived type's + // parent type CHECK(symbol.has()); return false; } -- cgit v1.1