[flang-commits] [PATCH] D132683: flang] Emit missing IMPORTs in module file interfaces

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Thu Aug 25 10:52:31 PDT 2022


klausler created this revision.
klausler added a reviewer: vdonaldson.
klausler added a project: Flang.
Herald added a subscriber: jdoerfert.
Herald added a reviewer: sscalpone.
Herald added a project: All.
klausler requested review of this revision.

[When a symbol from the enclosing scope is necessary to declare
a procedure or procedure pointer dummy argument or function result
for a procedure interface, note it in the collection of symbols to
be imported when scanning that interface.


https://reviews.llvm.org/D132683

Files:
  flang/lib/Semantics/mod-file.cpp
  flang/test/Semantics/modfile46.f90
  flang/test/Semantics/modfile49.f90


Index: flang/test/Semantics/modfile49.f90
===================================================================
--- /dev/null
+++ 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
Index: flang/test/Semantics/modfile46.f90
===================================================================
--- flang/test/Semantics/modfile46.f90
+++ 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
Index: flang/lib/Semantics/mod-file.cpp
===================================================================
--- flang/lib/Semantics/mod-file.cpp
+++ 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)}) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132683.455651.patch
Type: text/x-patch
Size: 2611 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220825/3f15ab65/attachment.bin>


More information about the flang-commits mailing list