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

    <tr>
        <th>Summary</th>
        <td>
            [flang][openmp] incorrect firstprivate initialization in omp task
        </td>
    </tr>

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

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

    <tr>
      <th>Reporter</th>
      <td>
          jeanPerier
      </td>
    </tr>
</table>

<pre>
    It looks like firstprivate initialization is not happening as expected in the program below: `i` in the `!omp task` is not given the value of `i` when the task is created (it seems it is given the value of `i` when the task is launched because it tends to be given `5` for instance).

I expect the program below to print "in task:  i=..." to print 1, 2,3 and 4 (in any order), but I see 5,5,5,5 (or sometimes 2,3,4,5).
 
````
subroutine test()
    use omp_lib, only : omp_get_thread_num
   implicit none
 integer :: i
!$omp parallel private(i)
   !$omp single
     do i = 1,4
 print '("outside: i= ",I0,"  thread_id= ",I0, "  &i= "I0)', i, omp_get_thread_num(), loc(i)
         !$omp task firstprivate(i)
 print '("in task: i= ",I0,"  thread_id= ",I0, "  &i= "I0)', i, omp_get_thread_num(), loc(i)
         !$omp end task
      end do
   !$omp end single
!$omp end parallel
end subroutine
 use omp_lib, only : omp_set_dynamic, omp_set_num_threads
 call omp_set_dynamic(.false.)
 call omp_set_num_threads(4)
 call test()
end
````

All of gfortran, nvfortran and ifx print 1,2,3,4 here (in random order of course).
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzMVc1u4zoPfRplQ0wgyz9xFl5kEhTo7nuDQrZpm1NZMiQ5M_2e_oK289MWGODubtEgCHl4yEORkg6BeotYifynyC87PcfB-eoXavs_9IR-V7v2o3qNYJx7D2DoHaEjH-Lk6aojAlmKpA39X0dyFiiAdREGPU1oyfagA-CfCZuILZCFOCBM3vVej1Cjcb9FegJRSBKFvPlFIYVK3DhB1OF9caysPV1xhVy1mRFcdw_9PWweD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