<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/116567>116567</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [Flang] Compilation error when subroutine is declared in interface-body in ancestor module and subroutine is declared in generic interface block in submodule
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            flang:frontend
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          ohno-fj
      </td>
    </tr>
</table>

<pre>
    ```
Version of flang-new : 20.0.0(7111d031f19ce7d523796b4812d6afcb2958b025)/AArch64
```

When `subroutine (f2) `is declared in `interface-body` in `ancestor module` and `subroutine (f2)` is declared in `generic interface block` in `submodule`, a compilation error occurs.

The following are the test program, Flang-new, Gfortran and ifx compilation/execution result.

sngg451h_2.f90:
```fortran
module m
  implicit none
  interface
    module subroutine sub(xv)
      integer::xv
 end subroutine sub
    module subroutine f2(k1)
 integer,intent(in)::k1
    end subroutine f2
  end interface
end module m

submodule (m) xx
  implicit none
  interface gen2
 procedure f2
  end interface
contains
  module subroutine sub(xv)
    integer::xv
    call gen2(xv)
  end subroutine sub
 module procedure f2
    if (k1/=2) print *,101
  end procedure f2
end submodule xx

program main
  use m
  call sub(2)
 print *,'pass'
end program main
```

```
$ flang-new sngg451h_2.f90
error: Semantic errors in sngg451h_2.f90
./sngg451h_2.f90:15:13: error: Procedure 'f2' is referenced before being sufficiently defined in a context where it must be so
 interface gen2
             ^^^^
$
```

```
$ gfortran sngg451h_2.f90; ./a.out
 pass
$
```

```
$ ifx sngg451h_2.f90; ./a.out
 pass
$
```

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVU1v4zYQ_TX0ZRBDHEm2ddDBm9S9FmjRHguKHEnclUiDpBLvvy-oD9uRk3ZbNBAUa0i-x3nzJbzXjSEqWf6F5S8bMYTWutK2xj7VXzeVVd9LtkvmJ3lhyf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