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

    <tr>
        <th>Summary</th>
        <td>
            [flang] Compilation error when specifying a subroutine name as an actual argument of a nested subroutine
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

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

<pre>
    ```
Version of flang-new : 17.0.0(dd3f7b02255a52b709797cdc6d121b113df9b4ab)
```

Compilation error when specifying a subroutine name as an actual argument of a nested subroutine. "call z(i)" on line 16 does not seem to call the subroutine (proc2). 

In gfortran and ifort, compilation and execution are possible.
In flang, I am able to compile by specifying the following in the subroutine (zz).
```
  external z
```

The following are the test program, flang-new, gfortran and ifort compilation result.


snggn433_2.f90:
```fortran
program main
  common j
  external proc2
  j=0
  call zz(proc2,1)
  if (j/=1)write(6,*) "NG"
  print *,'pass'
end program main

subroutine zz(z,i)
! external z
  call zzz(z,i)
end subroutine zz

subroutine zzz(z,i)
  call z(i)
  if (i/=1)write(6,*) "NG"
end subroutine zzz

subroutine proc2(i)
  common j
  j=j+1
  if (i/=1)write(6,*) "NG"
end subroutine proc2
```

```
$ flang-new -flang-experimental-exec snggn433_2.f90
./snggn433_2.f90:5:3: warning: If the procedure's interface were explicit, this reference would be in error
    call zz(proc2,1)
 ^^^^^^^^^^^^^^^^
./snggn433_2.f90:5:11: because: Actual argument 'proc2' associated with dummy argument 'z=' is not a variable or typed expression
 call zz(proc2,1)
            ^^^^^
./snggn433_2.f90:12:3: warning: If the procedure's interface were explicit, this reference would be in error
    call zzz(z,i)
    ^^^^^^^^^^^^^
./snggn433_2.f90:12:12: because: Actual argument associated with procedure dummy argument 'z=' is not a procedure
    call zzz(z,i)
             ^
error: loc("/home/users/ea01/ea0178/CT/fort/tp/reproducer/F95_35/snggn433_2.f90":12:3): 'fir.convert' op invalid type conversion
error: verification of lowering to FIR failed
$
```

```
$ gfortran snggn433_2.f90
snggn433_2.f90:12:15:

   call zzz(z,i)
 1
Warning: Type mismatch in argument 'z' at (1); passed REAL(4) to UNKNOWN [-Wargument-mismatch]
snggn433_2.f90:5:10:

   call zz(proc2,1)
          1
Warning: Invalid procedure argument at (1)
$ ./a.out
 pass
$
```

```
$ ifort snggn433_2.f90
$ ./a.out
 pass
$
```

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzEV99vozgQ_mucl1EQDCGEhzykzXKq7tSTVnu3jysDQ-LK2Mg2Tdu__mRIQn40u9vVnS6KCGA88818M98Qbq3YKKIlS-5Ysp7wzm21Weqt0tP6aVLo6nXJ5uH-G65ZuPqbjBVaga6hllxtpop2wOIVRGkQBiHDRVXFdVqEiEnCEyzSMEuztKzKeRVhVERRXNVZMeMFw2wweeFhON7rphWSO--LjNEGdltSYFsqRf0q1AY42K4wunNCESjeEHALXAEvXcclcLPpGlLOI-WgyDqqTnYEwBBLLiW8MVwIDwYRtALpzUVzqDRZUNqBJWrAaegfdls6dctw0RpdIsMsgFP4Dwo2tTbOeECqAuEvGN5DeRKXX6AXKrvhyhC02lpRSAqOVvok-40PwBvghaQeS2-FoHg9zYgHV2sp9c5fCfUO2rc3D_XdvAPQiyOjuE_JbWK-nDnxoL0XR9ZBa_TG8MajPdaGv7jOxFkaDNlOuuDUyXC0arNRszj-hkGdhSxeXcDamx3u7p1Dw4U6BFTqptEKnq4CHEjb331i8fqYg6Ek3kZi76NjoQKI2ifxiWHO4rVf2BnhiOFizvCe4Yph5uvq8TeGR_OtEcpBv3jPMG25tQzTYZVUBdfA99GPxPV43hjei7FpMLri64j--nHv6NzgLU_Xew9mD31ylgvxgVxcgbiFYp_6M3eXXHrWnhjeRf8anpOieLfyL2_i7EQCp8MpvbRkhNcdLqe-t-GiiPutAcP8qrgTFq9ir6Q7bpRQG3_6UPfd5ZFR1RlimFoQypGpe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