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

    <tr>
        <th>Summary</th>
        <td>
            [flang] Hit one assert when interface is different from the procedure definition
        </td>
    </tr>

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

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

    <tr>
      <th>Reporter</th>
      <td>
          PeixinQiao
      </td>
    </tr>
</table>

<pre>
    ```
$ cat test.f90
module m_test
  implicit none
  private
  public :: test

  interface test
     module procedure test_func
  end interface test

CONTAINS

  function test_func(i2) result(i1)
    implicit none
    real(8),dimension(:,:),target,intent(in):: i2
    real(8),pointer,dimension(:):: i1

    interface
       function ext_interface(ln,i2) result(i1)
       implicit none
       integer(4),intent(in) :: ln
       real(8),dimension(:,:),target,intent(in):: i2
       real(8),pointer,dimension(:):: i1
       end function ext_interface
    end interface

    i1 => ext_interface(size(i2),i2)
  end function test_func
end module m_test

function ext_interface(ln,i2) result(i1)
  implicit none
  integer(4),intent(in) :: ln
  real(8),dimension(ln),target,intent(in):: i2
  real(8),pointer,dimension(:):: i1
  i1 => i2
end function ext_interface
```
```
$ flang-new test.f90 -c
flang-new: /home/qpx/compilers/llvm-community/debug-mode/llvm-project/flang/lib/Optimizer/Builder/FIRBuilder.cpp:318: mlir::Value fir::FirOpBuilder::convertWithSemantics(mlir::Location, mlir::Type, mlir::Value, bool): Assertion `(fir::unwrapRefType(toTy) == fir::unwrapRefType(fir::unwrapPassByRefType(fromTy)) && "element types expected to match")' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
```
As Fortran 2018 15.4.3.2 (7), ff an explicit specific interface for an external procedure is specified by an interface body or a procedure declaration statement (15.4.3.6), the characteristics shall be consistent with those specified in the procedure definition, except that the interface may specify a procedure that is not pure even if the procedure is defined to be pure.

For this test case, are the characteristics be consistent? Or the question is what does it mean by "consistent"? Does it mean the "same"?

Should there be one semantic error or should it be supported in lowering? BTW, gfortran and ifort can support this.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy1Vl1vozgU_TXJi9WIQELJQx7Sj2hHGk2702rnsTJwSbxrbMY2bbO_fo8NSUib7mpmtBWi4X7fc64v5LrcLUdp1F_RzShajeIZK7hjjqybVIteWuuylcTqJy_uRIyJupGiEI4prWgvbIx45u742OawYaNkhYsdvQ8xlCNT8YLYMDL--oyN0QWVren0T1Wrir0RqfKse3e_vvvyuPr05eE0nfd3QqtBtDgT8SheMEO2lc4_TvF4rORslwzmXMI487bxdSlqUhaBIfK9xtfh7lWOmw0h7rWvVYUEyms6RJD7g5CNDs2dC35wnp52N4BzgOSga3p1T0eTOJPK1_Wv7X-MQJ9u42vMZl3Rpz3uaUeaodf_AN2voNf7-3H6AKiD2cnIvcN-in5vRsntO5it-Jv2c7YHfDjFZ6YyaL3uzMnr7j9P6lk-f5jKj1mU6sfo-wXmjpjvw_0XjW_X3fvtV0muNheKXg47kF30hBxUvopRvN7qGoivvzevuBe6boQkY_Fbyuf6AoK6VcLtICgpbzcXIJP2Wmy2P6kAKusQ1YtFjvtd40SNgQEC66tWyDL8Wn_62j9MiqZB-mTqMWG1FKZD5Q8uW2LV_nEtzF2z9w-SQqtnMu6bcNsHqrlyokCp2THCZ43FH-C-HsR93DV0KgmZvCjXWnassJW1iO0x91jG2aGOVr0Y3nylqouTOf246-YJtN2wD-3eKO65tVe7gdroOgQKseIUF_7FJAkzg7cXrCzob4AwlcxpVnNXbGERXC5ZxUFVOelovf98u3q4ZbbNa5wKzkAVhrLRxnnPrXONDfO3xrUBfG0-Abc9ke_5FNa25KeA8bAvCtmWeEFtiRWG2y3LefGXM5jIPv2Dg4CVbe15PTuWK8vWqMZwxeJomrHpfDKbJJMYLWeX3bFhVYV0vuXubFu0Liq8eo-vyEqbzgQCxeXg3Srs3h5g5TtvdXTL8ZXAvOvAoaRCchOmhVmH931AHdX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