diff --git a/flang/lib/Semantics/mod-file.cpp b/flang/lib/Semantics/mod-file.cpp --- a/flang/lib/Semantics/mod-file.cpp +++ b/flang/lib/Semantics/mod-file.cpp @@ -422,7 +422,12 @@ void ModFileWriter::PutSubprogram(const Symbol &symbol) { auto &details{symbol.get()}; if (const Symbol * interface{details.moduleInterface()}) { - PutSubprogram(*interface); + const Scope *module{FindModuleContaining(interface->owner())}; + if (module && module != &symbol.owner()) { + // Interface is in ancestor module + } else { + PutSubprogram(*interface); + } } auto attrs{symbol.attrs()}; Attrs bindAttrs{}; diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp --- a/flang/lib/Semantics/resolve-names.cpp +++ b/flang/lib/Semantics/resolve-names.cpp @@ -873,7 +873,7 @@ Symbol &PushSubprogramScope(const parser::Name &, Symbol::Flag, const parser::LanguageBindingSpec * = nullptr); Symbol *GetSpecificFromGeneric(const parser::Name &); - SubprogramDetails &PostSubprogramStmt(const parser::Name &); + SubprogramDetails &PostSubprogramStmt(); void CreateEntry(const parser::EntryStmt &stmt, Symbol &subprogram); void PostEntryStmt(const parser::EntryStmt &stmt); void HandleLanguageBinding(Symbol *, @@ -3422,8 +3422,7 @@ Walk(std::get(stmt.t)); Walk(std::get>(stmt.t)); // Don't traverse the LanguageBindingSpec now; it's deferred to EndSubprogram. - const auto &name{std::get(stmt.t)}; - auto &details{PostSubprogramStmt(name)}; + auto &details{PostSubprogramStmt()}; for (const auto &dummyArg : std::get>(stmt.t)) { if (const auto *dummyName{std::get_if(&dummyArg.u)}) { Symbol &dummy{MakeSymbol(*dummyName, EntityDetails{true})}; @@ -3444,7 +3443,7 @@ void SubprogramVisitor::Post(const parser::FunctionStmt &stmt) { const auto &name{std::get(stmt.t)}; - auto &details{PostSubprogramStmt(name)}; + auto &details{PostSubprogramStmt()}; for (const auto &dummyName : std::get>(stmt.t)) { Symbol &dummy{MakeSymbol(dummyName, EntityDetails{true})}; details.add_dummyArg(dummy); @@ -3509,8 +3508,7 @@ info.resultName = nullptr; } -SubprogramDetails &SubprogramVisitor::PostSubprogramStmt( - const parser::Name &name) { +SubprogramDetails &SubprogramVisitor::PostSubprogramStmt() { Symbol &symbol{*currScope().symbol()}; SetExplicitAttrs(symbol, EndAttrs()); if (symbol.attrs().test(Attr::MODULE)) { @@ -3775,7 +3773,7 @@ if (moduleInterface && &moduleInterface->owner() == &currScope()) { // Subprogram is MODULE FUNCTION or MODULE SUBROUTINE with an interface // previously defined in the same scope. - currScope().erase(moduleInterface->name()); + EraseSymbol(name); } } Symbol &newSymbol{PushSubprogramScope(name, subpFlag, bindingSpec)};