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

    <tr>
        <th>Summary</th>
        <td>
            [Flang] execution error when an intrinsic function name declared in an intrinsic statement is specified as an argument of a subroutine
        </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 : 18.0.0(1c876ff5155c4feeb2b2885eb3e6abda17c4b7f4)
```

When an intrinsic function name declared in an `intrinsic` statement is specified as an argument of a subroutine, the function cannot be used at the callee.

The following lines terminate abnormally at runtime..
```
  or(i)=func(arg(i))    ! Segmentation fault
```

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

ie500_dcos.f90:
```fortran
module moris
  intrinsic DCOS
  parameter(K=8)
  parameter(N=100)
 real(kind=8)::e=1.0d-14
  real(kind=K),dimension(N) :: arg,ir,or
 real(kind=4),dimension(N) :: tmp
end module moris

program main
 use  moris
  call random
  call outline(DCOS)
  call inline
  do i=1,n
     if(abs(ir(i)-or(i)).gt.e) then
        print*,"ng"
 print*,ir(i),or(i),abs(ir(i)-or(i))
     endif
  enddo
 print*,"DCOS ok"
end program main

subroutine random
  use moris
  INTEGER seed(33)/33*0/
  call random_seed(get=seed)
  do i=1,33
     seed(i)=seed(i)*5 /2  + 2
  enddo
  call random_seed(put=seed)
  call random_number(tmp)
  arg = tmp
end subroutine random

subroutine outline(func)
  use moris
 real(kind=k) :: func
  do i=1,n
     or(i)=func(arg(i))    ! Segmentation fault
  enddo
end subroutine outline

subroutine inline
  use  moris
  do i=1,n
     ir(i)=DCOS(arg(i))
 enddo
end subroutine inline
```

```
$ flang-new ie500_dcos_.f90; ./a.out
./ie500_dcos_.f90:13:3: warning: If the procedure's interface were explicit, this reference would be in error
 call outline(DCOS)
    ^^^^^^^^^^^^^^^^^^
./ie500_dcos_.f90:13:16: because: Actual argument associated with procedure dummy argument 'func=' is not a procedure
    call outline(DCOS)
 ^^^^
Segmentation fault (core dumped)
$
```

```
$ gfortran ie500_dcos_.f90; ./a.out
 DCOS ok
$
```

```
$ ifort ie500_dcos_.f90; ./a.out
 DCOS ok
$
```

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVlGPmzgQ_jXOy2gR2JDAQx7SpKmqSj3pWt09VgYPxK2xI9vctv_-ZJMssMlu1d6tsoDtGc_M52_Gw52TnUbckuINKQ4rPviTsVtz0uah_bqqjfixJev08ksPJN39hdZJo8G00CquuweNj0DYDrIySZOU0DJrys26bYusKJq8RaxpTcuywJrhmteCZ5smrzdtTmg1bvnMwvj8-4QauAapvZXayQbaQTc-mNa8RxDYKG5RgIxiZJ0-SZJ1Cs5zjz1qD9KBO2MjW4kCuAvC3HZDXDMtcHBDbc3gpUZC9-BPOFlquNbGQ40wuKDt43LDlUJM5t5-DlpGKfModQdKanTg0fZSc4_Aa21sz5X6Ebawg_ayxyS5Gz2AsYSWMqDDDsETQktuu-scrQAACM3gE3YhCB49bfmg_CtwLh3kFmMkHp2HszWd5X0I_ng90TB41xrrbYBLC5BhAI3pz1JFi4Qe8Ts2Q7Ru0Q3KLxCRWKTpF9EYl7RVStjumXOXzcfZ3ohBIfTGSneFYTr4w_6PT9fZM7e8R48Bow-EHconFi3XPhJ2yNJ0WrXIFaHlN6nFVY3tCNthEExS8ZDl132Woh8i6nshe9QuBl5-DKcwqkM8mr20hO6NvWsrf30D359HNdQCboEYn5czgp7LC2SBkbBELPASLNfC9IspM3gV2V1GJCfA4qrUcfEyJQzIgAih-6uh8CfbwMLaBRZe6fkwEZVWSecTDFH5E84VAeBspfaE7gjdE0p1Ryi9CMxW5LTXfrbv_jWbMzOohWyvY9RCmFsThNIQP5hvTx4EyG-hHZ9TWXiGaQB-gfv7j5_fvnv7JzhEQWjJWHTvGN67l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