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 @@ -1185,6 +1185,12 @@ DoSymbol(*object); } }, + [this](const ProcEntityDetails &details) { + if (const Symbol * symbol{details.interface().symbol()}) { + DoSymbol(*symbol); + } + DoType(details.interface().type()); + }, [](const auto &) {}, }, symbol.details()); @@ -1241,6 +1247,8 @@ const SourceName &name, const Symbol &symbol) { if (!isInterface_) { return false; + } else if (&symbol == scope_.symbol()) { + return false; } else if (symbol.owner().Contains(scope_)) { return true; } else if (const Symbol * found{scope_.FindSymbol(name)}) { diff --git a/flang/test/Semantics/modfile46.f90 b/flang/test/Semantics/modfile46.f90 --- a/flang/test/Semantics/modfile46.f90 +++ b/flang/test/Semantics/modfile46.f90 @@ -39,17 +39,17 @@ !contains !function f(x) !real(4),intent(in)::x -!procedure(used_int),pointer::f !abstract interface !subroutine used_int(x,p) !real(4),intent(out)::x -!procedure(inner_int)::p !interface !subroutine inner_int(x) !real(4),intent(out)::x !end !end interface +!procedure(inner_int)::p !end !end interface +!procedure(used_int),pointer::f !end !end diff --git a/flang/test/Semantics/modfile49.f90 b/flang/test/Semantics/modfile49.f90 new file mode 100644 --- /dev/null +++ b/flang/test/Semantics/modfile49.f90 @@ -0,0 +1,41 @@ +! RUN: %python %S/test_modfile.py %s %flang_fc1 +! Ensure that symbols and types needed to declare procedures and procedure pointers +! are properly imported into interfaces. +module m + type :: t + end type + procedure(sin) :: ext + interface + subroutine subr(p1,p2) + import ext, t + procedure(ext) :: p1 + procedure(type(t)), pointer :: p2 + end subroutine + function fun() result(res) + import subr + procedure(subr), pointer :: res + end function + end interface +end module + +!Expect: m.mod +!module m +!type::t +!end type +!intrinsic::sin +!procedure(sin)::ext +!interface +!subroutine subr(p1,p2) +!import::ext +!import::t +!procedure(ext)::p1 +!procedure(type(t)),pointer::p2 +!end +!end interface +!interface +!function fun() result(res) +!import::subr +!procedure(subr),pointer::res +!end +!end interface +!end