Issue 76345
Summary [Flang][OpenMP] Incorrect execution result when a threadprivate variable is defined using parallel construct in subroutine
Labels openmp, flang
Assignees
Reporter ohno-fj
    ```
Version of flang-new : 18.0.0(76bbbcb41bcf4a1d7a26bb11b78cf97b60ea7d4b)
```

The value of a variable (declared in `threadprivate` clause) defined in `parallel` construct in subroutine is incorrect in the caller's `parallel` construct.

If subroutine is deployed to the caller, the result is correct. Attach the example program (sngg492a_3.f90) and its results to the end.

The following are the test program, Flang-new, Gfortran and ifort compilation/execution result.

sngg492a_2.f90:
```fortran
subroutine s1
 complex,save:: a1
!$omp threadprivate(a1)
  call set_th
  print *, 300,a1
!$omp parallel
  print *,301,a1
!$omp end parallel
contains
  subroutine set_th
!$omp parallel
    a1%re=1. + 2.
    a1%im=2. + 2.
!$omp end parallel
  end subroutine set_th
end subroutine s1

program main
  call s1
  print *,'pass'
end program main
```

```
$ export OMP_NUM_THREADS=2; flang-new -fopenmp sngg492a_2.f90; ./a.out
 300 (3.,4.)
 301 (3.,4.)
 301 (0.,0.)
 pass
$
```

```
$ export OMP_NUM_THREADS=2; gfortran -fopenmp sngg492a_2.f90; ./a.out
         300 (3.00000000,4.00000000)
         301 (3.00000000,4.00000000)
         301 (3.00000000,4.00000000)
 pass
$
```

```
$ export OMP_NUM_THREADS=2; ifort -qopenmp sngg492a_2.f90; ./a.out
         300 (3.000000,4.000000)
         301 (3.000000,4.000000)
         301 (3.000000,4.000000)
 pass
$
```

sngg492a_3.f90:
```fortran
subroutine s1
 complex,save:: a1
!$omp threadprivate(a1)
!$omp parallel
  a1%re=1. + 2.
  a1%im=2. + 2.
!$omp end parallel
  print *, 300,a1
!$omp parallel
  print *,301,a1
!$omp end parallel
end subroutine s1

program main
  call s1
  print *,'pass'
end program main
```

```
$ export OMP_NUM_THREADS=2; flang-new -fopenmp sngg492a_3.f90; ./a.out
 300 (3.,4.)
 301 (3.,4.)
 301 (3.,4.)
 pass
$
```

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to