Skip to content

[Flang][OpenMP][Task] Loop iteration variable treated as firstprivate instead of private in task construct #140882

Closed
@kaviya2510

Description

@kaviya2510

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:

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

  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>)
  }

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions