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

    <tr>
        <th>Summary</th>
        <td>
            [Flang] Segmentation fault in an assignment statement as an array with a subscript in FORALL construct
        </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 : 17.0.0(f6c4808d95221a5838e14474d95c6fe85bb1488a)
AArch64
```

An assignment statement using an array as an array index in the `FORALL` construct results in a segmentation fault. 
Changing the array index from v (i) to i, as shown below,  result in successful compilation.

- Before the change
```
forall (i = 1: 5)
v (i) = i
b (v (i): v (i)) = mod 01 _ fun1 (a (v (i): v (i)))
end forall
```
- After the change
```
forall (i = 1: 5)
b (i: i) = mod01 _ fun1 (a (i: i))
end forall
```

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

snf95_120_2.f90:
```fortran
program main
  call test01()
  print *,'pass'
end program main

module mod01
contains
  elemental function mod01_fun1(i) result(ifun)
 intent(in) :: i
    ifun=i
  end function mod01_fun1
end module mod01

subroutine test01()
  use mod01
  integer v(5),a(5),b(5)
  a=reshape((/(i,i=1,5)/),(/5/))
  b=0
  write(6,*) "a = ", a
  forall (i=1:5)
     v(i)=i
 b(v(i):v(i))=mod01_fun1(a(v(i):v(i)))
  end forall
  write(6,*) "b = ", b
  if (any(a.ne.b)) write(6,*) "NG"
end subroutine test01
```

```
$ flang-new -flang-experimental-exec snf95_120_2.f90; ./a.out
 a =  1 2 3 4 5
Segmentation fault (core dumped)
$
```

```
$ gfortran snf95_120_2.f90; ./a.out
 a = 1           2           3           4           5
 b = 1           2           3           4           5
 pass
$
```

```
$ ifort snf95_120_2.f90; ./a.out
 a = 1           2           3           4           5
 b =            1 2           3           4           5
 pass
$
```

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8VluPozYU_jXOy1EQHC6BhzywibIvq1Zqq76OjDHBK2JHtpns_PvKNgF2klmtulWjEWMfzuX7zsWYGiPOkvM9yT-R_Liho-2V3qteqm33ddOo9m1Pinj6i48krv_m2gglQXXQDVSet5LfgKQ1JLsojmKCZVewrIzLtsoRE5qXacmTLNtlbZWzouNl3jRJVpaUYBVc1rVmfZGFzbtwk4aEAPXCpQVjqeV-NRohz0AlUK3pG1CzrIVs-TcQEmzPgRTx6fc_6i9fSBEDU9JYPTILmptxsMZpUTD87HxS69h1dBxsBCH6oafy7AI5V2vvnVYXeAWCpSBYgVUgCB4cDNOrm4SGD-rmJFMkF8iMjHFjunEApi5XMfiA0ZrtFj7xTmnu4zEXnD_NTac0HQYfHkh6hMSVIZ_TugBzL0UQNk44v3EGy2bSvKgW4gReoBtl4l7SH9rM8bhsIUB6inYLdWe5_kVSTYic1iBWeB_hzio_Cy88_-o5dGoY1M031lQDy42Fq1ZnTS-unPe-UR2c7jPg5J87pa12LShbEG6zrrGX8m-cjQ8VN7Kr8pcE4xeMuiomaf0O4-Q4SCckcKFikgAwlzSHM04IljNpgKsW0gLBmuCB4O5KjSG4W1Ly6Cw8L6odBx6SGyRMSUuFNHfPfPBDSAeXeeYZeu0XV4h764VUuV03ygWWkJZLL5ahjHWo1-QawKunx1niq_ckzMzjEe-U2rHRarRC8qfpGc13NuCRnbmGV4Klbzs80GXZ3JeTNiXpUXPT0yv3fkuCp0D9IEh6TAgeguUp2AeN_L6f_TQkPcb3zU0L69wV3qD2CUKkvtkJoj9i7rqrcfHx0noND8DzCGM7J9ORWMT162qW0-N3JaQfay5B3g_WRwSaNYFmznfnZ1a-uWckedRMR9FzJ799dg7mqj9W9-PZfi_EbPUF24Yl_3blWoS23rpZhYfR_AQRwRON1GgnDqEykABCChnkQfznw_fEEWXuXG_Hy5W3cwoJ_ujb9wT2-X7O_DS4BJYfrtbpap2t1vm9VX7J2h82_45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