Peter Klausler a3e9d3c2c7
[flang] Allow reference to earlier generic in later interface
Name resolutions defers all resolution and checking of specific procedures
in non-type-bound generic interfaces to the end of the specification part.
This prevents expression analysis of references to generic functions in
specification expressions in interfaces from resolving.

Example (now a new test case in modfile07.f90):
```
  module m12
    interface generic
      module procedure specific
    end interface
    interface
      module subroutine s(a1,a2)
        character(*) a1
        character(generic(a1)) a2   ! <--
      end
    end interface
   contains
    pure integer function specific(x)
      character(*), intent(in) :: x
      specific = len(x)
    end
  end
```

The solution is to partially resolve specific procedures as they are
defined for each generic, when they can be resolved, with the final
pass at the end of the specification part to finish up any forward
references and emit the necessary error messages.

Making this fix caused some issues in module file output, which have
all been resolved by making this simplifying change: generics are
now all emitted to module file specification parts as their own
group of declarations at the end of the specification part,
followed only by namelists and COMMON blocks.

Differential Revision: https://reviews.llvm.org/D157346
2023-08-08 12:19:53 -07:00

49 lines
828 B
Fortran

! RUN: %python %S/test_modfile.py %s %flang_fc1
! Resolution of specification expression references to generic interfaces
! that resolve to private specific functions.
module m1
interface gen
module procedure priv
end interface
private :: priv
contains
pure integer function priv(n)
integer, intent(in) :: n
priv = n
end function
end module
!Expect: m1.mod
!module m1
!private::priv
!interface gen
!procedure::priv
!end interface
!contains
!pure function priv(n)
!integer(4),intent(in)::n
!integer(4)::priv
!end
!end
module m2
use m1
contains
subroutine s(a)
real :: a(gen(1))
end subroutine
end module
!Expect: m2.mod
!module m2
!use m1,only:gen
!use m1,only:m1$m1$priv=>priv
!private::m1$m1$priv
!contains
!subroutine s(a)
!real(4)::a(1_8:int(m1$m1$priv(1_4),kind=8))
!end
!end
use m2
end