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

    <tr>
        <th>Summary</th>
        <td>
            [Flang] Execution error when a variable with optional and pointer attributes defined is used as an argument to a subroutine
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            flang
      </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(2603c8b23be06116bc61bda36fae05b81d906c3f)/AArch64
```

When a variable with `optional` and `pointer` attributes defined is used as an argument to a `subroutine`, a run-time error occurs (`Segmentation fault (core dumped)`).  
When `pointer` attribute is changed to `allocatable` attribute, the execution also fails.  
When `pointer` and `allocatable` attributes are not specified, the execution succeeds.


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

F01_12.f90:
```fortran
program main
  call sub3()
  print*,"Pass"
contains
  subroutine sub3(ptr)
    integer,optional,pointer :: ptr(:)       ! Segmentation fault
!    integer,optional,allocatable :: ptr(:)  ! Segmentation fault
!    integer,optional :: ptr(:)              ! OK
    call sub(ptr)
  end subroutine sub3
  subroutine sub(dmy)
 integer,optional::dmy(:)
    write(6,*) "present(dmy) = ", present(dmy)
  end subroutine sub
end program main
```

```
$ flang-new F01_12.f90; ./a.out
Segmentation fault (core dumped)
$
```

```
$ gfortran F01_12.f90; ./a.out
 present(dmy) =  F
 Pass
$
```

```
$ ifort -diag-disable=10448 F01_12.f90; ./a.out
 present(dmy) =  F
 Pass
$
```

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