[flang-commits] [flang] 82bd7ad - [flang] Fix bug introduced by PR#93106 (#93326)
via flang-commits
flang-commits at lists.llvm.org
Fri May 24 14:26:58 PDT 2024
Author: Peter Klausler
Date: 2024-05-24T14:26:54-07:00
New Revision: 82bd7adb97e41fa6b6150942ae55ef35efb63e2b
URL: https://github.com/llvm/llvm-project/commit/82bd7adb97e41fa6b6150942ae55ef35efb63e2b
DIFF: https://github.com/llvm/llvm-project/commit/82bd7adb97e41fa6b6150942ae55ef35efb63e2b.diff
LOG: [flang] Fix bug introduced by PR#93106 (#93326)
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.
Added:
Modified:
flang/lib/Semantics/mod-file.cpp
flang/test/Semantics/modfile03.f90
Removed:
################################################################################
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
More information about the flang-commits
mailing list