Index: flang/lib/Semantics/mod-file.cpp =================================================================== --- flang/lib/Semantics/mod-file.cpp +++ 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{}; Index: flang/lib/Semantics/resolve-names.cpp =================================================================== --- flang/lib/Semantics/resolve-names.cpp +++ 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 *, @@ -3416,8 +3416,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})}; @@ -3438,7 +3437,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); @@ -3503,8 +3502,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)) { @@ -3769,7 +3767,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)};