[flang-commits] [flang] [flang] Fix bug introduced by PR#93106 (PR #93326)

via flang-commits flang-commits at lists.llvm.org
Fri May 24 10:34:32 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-semantics

Author: Peter Klausler (klausler)

<details>
<summary>Changes</summary>

https://github.com/llvm/llvm-project/pull/93106 introduced some necessary fixes to module file generation, but has also caused a regression.  The module file output can include bogus attempts to USE-associate symbols local to derived type scopes, like components and bindings.  Fix, and extend a test.

---
Full diff: https://github.com/llvm/llvm-project/pull/93326.diff


2 Files Affected:

- (modified) flang/lib/Semantics/mod-file.cpp (+3) 
- (modified) flang/test/Semantics/modfile03.f90 (+49) 


``````````diff
diff --git a/flang/lib/Semantics/mod-file.cpp b/flang/lib/Semantics/mod-file.cpp
index 67523c468f18d..d7f149467dd7a 100644
--- a/flang/lib/Semantics/mod-file.cpp
+++ b/flang/lib/Semantics/mod-file.cpp
@@ -290,6 +290,9 @@ void ModFileWriter::PrepareRenamings(const Scope &scope) {
   // to their names in this scope, creating those new names when needed.
   auto &renamings{context_.moduleFileOutputRenamings()};
   for (SymbolRef s : symbolsNeeded) {
+    if (s->owner().kind() == Scope::Kind::DerivedType) {
+      continue; // component or binding: ok
+    }
     const Scope *sMod{FindModuleContaining(s->owner())};
     if (!sMod || sMod == &scope) {
       continue;
diff --git a/flang/test/Semantics/modfile03.f90 b/flang/test/Semantics/modfile03.f90
index 39f56ca41584d..eb3136f0aa8bc 100644
--- a/flang/test/Semantics/modfile03.f90
+++ b/flang/test/Semantics/modfile03.f90
@@ -222,3 +222,52 @@ subroutine foo(x,a)
 !real(4)::a(1_8:int(m8a$foo(10_4),kind=8))
 !end
 !end
+
+module m9a
+  private
+  public t
+  type t
+    integer n
+   contains
+    procedure f
+  end type
+ contains
+  pure integer function f(x, k)
+    class(t), intent(in) :: x
+    integer, intent(in) :: k
+    f = x%n + k
+  end
+end
+!Expect: m9a.mod
+!module m9a
+!type::t
+!integer(4)::n
+!contains
+!procedure::f
+!end type
+!private::f
+!contains
+!pure function f(x,k)
+!class(t),intent(in)::x
+!integer(4),intent(in)::k
+!integer(4)::f
+!end
+!end
+
+module m9b
+  use m9a
+ contains
+  subroutine s(x, y)
+    class(t), intent(in) :: x
+    real y(x%f(x%n))
+  end
+end
+!Expect: m9b.mod
+!module m9b
+!use m9a,only:t
+!contains
+!subroutine s(x,y)
+!class(t),intent(in)::x
+!real(4)::y(1_8:int(x%f(x%n),kind=8))
+!end
+!end

``````````

</details>


https://github.com/llvm/llvm-project/pull/93326


More information about the flang-commits mailing list