This is an archive of the discontinued LLVM Phabricator instance.

[flang] Allow reference to earlier generic in later interface
ClosedPublic

Authored by klausler on Aug 7 2023, 3:37 PM.

Details

Summary

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.

Diff Detail

Event Timeline

klausler created this revision.Aug 7 2023, 3:37 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 7 2023, 3:37 PM
klausler requested review of this revision.Aug 7 2023, 3:37 PM
PeteSteinfeld accepted this revision.Aug 7 2023, 6:35 PM

All builds and tests correctly and looks good.

This revision is now accepted and ready to land.Aug 7 2023, 6:35 PM