<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/140882>140882</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[Flang][OpenMP][Task] Loop iteration variable treated as firstprivate instead of private in task construct
</td>
</tr>
<tr>
<th>Labels</th>
<td>
flang:openmp
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
kaviya2510
</td>
</tr>
</table>
<pre>
According to the OpenMP specification, ***Loop iteration variables inside parallel, teams, or task generating constructs are **private** in the innermost such construct that encloses the loop.***
In the following example:
```fortran
subroutine test()
integer :: x
!$omp task
do i = 1, 10
x = 1
end do
!$omp end task
end subroutine
```
The loop iteration variable `i` must be treated as `private` to task. However, the current behavior treats `i` as `firstprivate`, which is incorrect.
Here is the generated FIR which treats the variable `i` as `firstprivate` : [Godbolt link](https://godbolt.org/z/Pe3Yo9P5Y)
```mlir
omp.private {type = firstprivate} @_QFtestEx_firstprivate_i32 : i32 copy {
^bb0(%arg0: !fir.ref<i32>, %arg1: !fir.ref<i32>):
%0 = fir.load %arg0 : !fir.ref<i32>
hlfir.assign %0 to %arg1 : i32, !fir.ref<i32>
omp.yield(%arg1 : !fir.ref<i32>)
}
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJx0VN9vozgQ_msmL6NFxoQkPPCQbsrtSne63mlf9qkyZgBfjY1skzb3158MtMl1WwkJmPH3zTc_PMJ71RmiEvI7yE8bMYXeuvJJnNVF8Dxlm9o2l_IopXWNMh0Gi6En_HMk88cD-pGkapUUQVkD_CsCPy7P79aOqAK52YVn4ZSoNXlUxquGcBROaE06ggKJwccP6zAI_4QdmRloOpTW-OAmGTwKRyv_6NRZBFp-UJlZkjKG3GB9QD_J_grE0IuAZKS2nvx8VFs7Jm9SgcXn-8LSWq3tc4xML2IYNUG2HoAdW57WuuCEAXb0U-3sFJQhDOQD8APwAtgRUZlAHTmM6OyIL7MReA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