[flang-commits] [flang] [flang][OpenMP] Diagnose privatized array section reductions (PR #215997)
via flang-commits
flang-commits at lists.llvm.org
Mon Aug 17 01:02:59 PDT 2026
MattPD wrote:
You're right. Under [OpenMP 5.0, section 2.19.5.1](https://www.openmp.org/spec-html/5.0/openmpsu107.html#x140-5810002.19.5.1), the access to `a(1)` gives my original reproducer unspecified behavior. Thanks for catching it.
The replacement below uses a user-defined reduction. Its `taskloop` body accesses only `a(2:3)`, the section named in the reduction clause:
```fortran
subroutine s(a)
integer :: a(4), i
!$omp declare reduction(myred : integer : omp_out = omp_out + omp_in) &
!$omp& initializer(omp_priv = 1)
!$omp taskloop reduction(myred : a(2:3))
do i = 1, 1
a(2:3) = a(2:3) + i
end do
end
```
With delayed privatization disabled, Flang emits a four-element array reduction for `myred : a(2:3)`. The initializer fills all four elements with 1. The combiner iterates from 1 through 4.
The specification requires a separate reduction for each element of an array section. Only `a(2)` and `a(3)` should participate. The generated HLFIR also combines `a(1)` and `a(4)`.
The incorrect lowering therefore remains on that path for a program with defined behavior.
https://github.com/llvm/llvm-project/pull/215997
More information about the flang-commits
mailing list