[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.
This commit is contained in:
Peter Klausler 2024-05-24 14:26:54 -07:00 committed by GitHub
parent 90e33e20a5
commit 82bd7adb97
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 52 additions and 0 deletions

View File

@ -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;

View File

@ -222,3 +222,52 @@ end
!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