[PATCH] D79737: [flang] Fix bug with IMPORT of USE of USE

Tim Keith via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 11 12:23:10 PDT 2020


tskeith created this revision.
tskeith added reviewers: klausler, PeteSteinfeld.
tskeith added a project: Flang.
Herald added a reviewer: jdoerfert.
Herald added a reviewer: DavidTruby.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
klausler accepted this revision.
klausler added a comment.
This revision is now accepted and ready to land.

LGTM


When a module contained an import of a use-association of a
use-association, we weren't recognizing that the symbols was needed.
The fix is the follow all of the use-associations using `GetUltimate()`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D79737

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


Index: flang/test/Semantics/modfile36.f90
===================================================================
--- /dev/null
+++ flang/test/Semantics/modfile36.f90
@@ -0,0 +1,41 @@
+! RUN: %S/test_modfile.sh %s %t %f18
+
+! Check modfile that contains import of use-assocation of another use-association.
+
+module m1
+  interface
+     subroutine s(x)
+       use, intrinsic :: iso_c_binding, only: c_ptr
+       type(c_ptr) :: x
+     end subroutine
+  end interface
+end module
+!Expect: m1.mod
+!module m1
+! interface
+!  subroutine s(x)
+!   use iso_c_binding, only: c_ptr
+!   type(c_ptr) :: x
+!  end
+! end interface
+!end
+
+module m2
+  use, intrinsic :: iso_c_binding, only: c_ptr
+  interface
+     subroutine s(x)
+       import :: c_ptr
+       type(c_ptr) :: x
+     end subroutine
+  end interface
+end module
+!Expect: m2.mod
+!module m2
+! use iso_c_binding,only:c_ptr
+! interface
+!  subroutine s(x)
+!   import::c_ptr
+!   type(c_ptr)::x
+!  end
+! end interface
+!end
Index: flang/lib/Semantics/mod-file.cpp
===================================================================
--- flang/lib/Semantics/mod-file.cpp
+++ flang/lib/Semantics/mod-file.cpp
@@ -833,7 +833,7 @@
   for (const auto &pair : scope_) {
     const Symbol &symbol{*pair.second};
     if (const auto *useDetails{symbol.detailsIf<UseDetails>()}) {
-      if (useSet_.count(useDetails->symbol()) > 0) {
+      if (useSet_.count(useDetails->symbol().GetUltimate()) > 0) {
         need_.push_back(symbol);
       }
     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D79737.263241.patch
Type: text/x-patch
Size: 1509 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200511/d45c8bec/attachment.bin>


More information about the llvm-commits mailing list