<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/71914>71914</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[Flang][OpenMP] default(private) failing with parallel do
</td>
</tr>
<tr>
<th>Labels</th>
<td>
flang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
NimishMishra
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
NimishMishra
</td>
</tr>
</table>
<pre>
`default(private)` fails to privatize when used with parallel do. Reproducer:
```
program sample
integer :: x
x = 0
!$omp parallel do default(private) num_threads(50)
do i = 1, 50
x = x + 1
end do
!$omp end parallel do
print *, x
end program sample
```
As expected, gfortran prints x=0. However, LLVM flang prints a non-zero value (< 50). Use of an additional `if(.false.)` ensures x=50.
A dump of `--emit-fir` shows `fir.store %10 to %1`
```
%0 = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFEi"}
%1 = fir.alloca i32 {bindc_name = "x", uniq_name = "_QFEx"}
%c0_i32 = arith.constant 0 : i32
fir.store %c0_i32 to %1 : !fir.ref<i32>
%c50_i32 = arith.constant 50 : i32
omp.parallel num_threads(%c50_i32 : i32) {
%8 = fir.alloca i32 {adapt.valuebyref, pinned}
%c1_i32 = arith.constant 1 : i32
%c50_i32_0 = arith.constant 50 : i32
%c1_i32_1 = arith.constant 1 : i32
omp.wsloop for (%arg0) : i32 = (%c1_i32) to (%c50_i32_0) inclusive step (%c1_i32_1) {
fir.store %arg0 to %8 : !fir.ref<i32>
%9 = fir.load %1 : !fir.ref<i32>
%c1_i32_2 = arith.constant 1 : i32
%10 = arith.addi %9, %c1_i32_2 : i32
**fir.store %10 to %1 : !fir.ref<i32>**
omp.yield
}
omp.terminator
}
```
Expected IR should be as follows:
```
%0 = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFEi"}
%1 = fir.alloca i32 {bindc_name = "x", uniq_name = "_QFEx"}
%c0_i32 = arith.constant 0 : i32
fir.store %c0_i32 to %1 : !fir.ref<i32>
%c50_i32 = arith.constant 50 : i32
omp.parallel num_threads(%c50_i32 : i32) {
%8 = fir.alloca i32 {adapt.valuebyref, pinned}
**%9 = fir.alloca i32 {bindc_name = "x", pinned, uniq_name = "_QFEx"}**
%c1_i32 = arith.constant 1 : i32
%c50_i32_0 = arith.constant 50 : i32
%c1_i32_1 = arith.constant 1 : i32
omp.wsloop for (%arg0) : i32 = (%c1_i32) to (%c50_i32_0) inclusive step (%c1_i32_1) {
fir.store %arg0 to %8 : !fir.ref<i32>
%10 = fir.load %9 : !fir.ref<i32>
%c1_i32_2 = arith.constant 1 : i32
%11 = arith.addi %10, %c1_i32_2 : i32
**fir.store %11 to %9 : !fir.ref<i32>**
omp.yield
}
omp.terminator
}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzkV12P4jYU_TXm5YrIdggkDzwww6JW2u3HSu0rcvANuHLs1HYGZn995RAYMgOzdFeqtKo0yoB977lfxydYeK-2BnFOsgfC-S-qVn73SfmdE4Rzki1Hog076-aXO6PSyuc5mVKJlWh1IDxvnHoSAQkvyJRCJZT2ECwcl9UXhP0ODbQeJexV2EEjnNAaNUibwGdsnJXtBh1JF4QuCT09p7T_6742zm6dqMGLutF4XAMAZQJu0UF0ThdwOG8cgKRL6J2BcEb4xNbNZXC4VgKYtl6HnUMhPeF5RmNZJ1CA6KY6aEb4I2SnAMdwByD8AdilPRoJ0p5XXhKJGxfJnC0ap0wAwhcRv6-ns73SgFc9Oj4XHvDQ4CagjBDbyrrghDkCeziQdEkT-Mnu8QldtPj48c9PUGlhticbAcaa8Rd0Fp6EbhEIz0nalcuLBP7wCLYCYUBIqYKyRmggU6oqwvOkEtpj0rMBjW8dHqNmNBnkCbKtmwhEpnQ8xlqFcaVc9PI7u_dxuVIu8cG6mEHGaKRV_PCq4ldtgK7PGe1GEhGE1nYjQKUcyOyhVEZu1kbU2BkQzlWkO3-E1qi_Bxvr31cfus3ZcgDN7oY-vAd9uAK9oesOLF2CcCrsko01P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