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

    <tr>
        <th>Summary</th>
        <td>
            [Flang][OpenMP] Incorrect execution result when reduction-identifier of reduction clause is specified as + and an array with a subscript of 0 is used in the reduction operation
        </td>
    </tr>

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

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

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

<pre>
    ```
Version of flang : 21.0.0(3e6f618e86f5fbad2c2d5802416ec3d3366a2837)/AArch64
```

In `parallel do reduction` directive, when `reduction-identifier` of `reduction` clause is specified as `+` and an array with a subscript of 0 is used for the `reduction` operation, the result is incorrect.  
The result of the reduction operation does not appear to be assigned.  
The above program is `test132.f90`.

When an array with a subscript of 1 is used in the `reduction` operation, the result is correct.  
The above program is `test131.f90`.

The following are the test program, Flang, Gfortran and ifx compilation/execution result.

test132.f90:
```fortran
program main
 integer a(0:1)
  a=0
!$omp parallel do reduction(+:a)
  do i=1,10
 a(0)=a(0)+1
  enddo
!$omp end parallel do
  write(6,*) "a(0) = ", a(0)
 end program main
```

```
$ export OMP_NUM_THREADS=2; flang -fopenmp test132.f90; ./a.out
flang-20: warning: OpenMP support in flang is still experimental [-Wexperimental-option]
 a(0) =  0
$
```

```
$ export OMP_NUM_THREADS=2; gfortran -fopenmp test132.f90; ./a.out
 a(0) = 10
$
```

```
$ export OMP_NUM_THREADS=2; ifx -qopenmp test132.f90; ./a.out
 a(0) =           10
$
```

test131.f90:
```fortran
program main
  integer a(0:1)
  a=0
!$omp parallel do reduction(+:a)
  do i=1,10
     a(1)=a(1)+1
  enddo
!$omp end parallel do
  write(6,*) "a(1) = ", a(1)
 end program main
```

```
$ export OMP_NUM_THREADS=2; flang -fopenmp test131.f90; ./a.out
flang-20: warning: OpenMP support in flang is still experimental [-Wexperimental-option]
 a(1) =  10
$
```

```
$ export OMP_NUM_THREADS=2; gfortran -fopenmp test131.f90; ./a.out
 a(1) = 10
$
```

```
$ export OMP_NUM_THREADS=2; ifx -qopenmp test131.f90; ./a.out
 a(1) =           10
$
```


</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzEVlFv2zYQ_jX0y8EGebRk-cEPcjRvfchabN36WNDiyWYhkxpJJem_HyjLsd0mQ4JlnWDAovTxu_tO90mnQjA7S7Ri2Zpl1UT1ce_8yu2tmzZfJlunv65YzscfL_8kH4yz4BpoWmV3wGQJKGZ8xhkWkvImFwUVeZM1W6WxRp0VHOcip1pqKfNcYSEXDJcMN2Xp630-Z7y8jMB4-c4Cy3mnvGpbakE78KT7OhpnWc5BG091NHfE8Abu9zSgHxFTo8lG0xjyCeyaq7vpUt2qPhCYAKGjOiE1qJBgDNcJoKwGZUF5r77CvYl7UBD6bai96WJi5GlzH0hD4zzEPX0Xw3Xk1bDAmwHgKfRtTPuMrZ1PCmYAjJcfzzddM0JHojMLaEcBrIuguo6Uh-hgSzA-PX1mUlt3R9B5t_PqkKKxnEcKUUicNctU4tmxxp9S3f5RpHgUaexrNX6n8Pm8xHVeCdy4tnX3xu5AeRqYE_S0O0XbpN5LJz83zkefdFgNpnmA2h06045pbeiB6n4o4DG3MchlRWR52YAjHePlKdeDMmkJxkbakQfFsEi7RGpiXgIoJquhcVEwnLtDB093LhapvWSpThu1A8NkJRjeiEQwUuOSyerxFNdiAJPV2l1FIasvIw2oe28iMSxyhjcMS4ZLYIgnMmCySutUuMcAvDwyXcv9xpFXS5wDPXTOR3h_--Hzr3_cfv74y28_ldXvTFbI5Hp8M0wb15E9dHBV7TXMGG7UzPWR8XJATjHVE-6Vt8bu0un7juztBwh9N4QxdqRMlo2mbVN88uZANqoWWLaefrq8MnXdUPGsuqzqoB5GBf9W4u7Udy9ReZ2CeKMUUrdP_3pt9PPxfB6XxnypPX6EP9KR6MXZI-ItPSKe8Ij4kR4R_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