Commit 4aeb31f
committed
[OpenMP] Address __kmp_dist_for_static_init issue
This patch attempts to provide a fix for an issue that appears when the
`__kmp_dist_for_static_init` function is called from a serialized team.
This is triggered by code generated by flang for `distribute parallel do`
constructs whenever an `if` clause for the `parallel` leaf construct is
present. This results in the introduction of a call to `__kmpc_fork_call_if` in
place of `__kmpc_fork_call`. When it evaluates to `false`, it defers execution
to `__kmp_serialized_parallel`, which creates a new serial team that is picked
up by `__kmp_dist_for_static_init`, resulting in an incorrect `team` pointer
that causes the `nteams == (kmp_uint32)team->t.t_parent->t.t_nproc` assertion
to fail.
The sequence of calls replicating this issue can be summarized as:
- __kmpc_fork_teams
- __kmpc_fork_call_if
- __kmpc_dist_for_static_init_*
Since I am not familiar with the implementation of the OpenMP runtime, it is
possible that the previous sequence of calls is incorrect, or that the bug can
be better fixed in another way, so I am open to discussing this.
The following Fortran program can be compiled with flang to show the issue:
```f90
! Compile and run: flang -fopenmp test.f90 -o test && ./test
! Check LLVM IR: flang -fc1 -emit-llvm -fopenmp test.f90 -o -
program main
implicit none
integer, parameter :: n = 10
integer :: i, idx(n)
!$omp teams
!$omp distribute parallel do if(.false.)
do i=1,n
idx(i) = i
end do
!$omp end teams
print *, idx
end program
```1 parent 3dc7991 commit 4aeb31f
1 file changed
+4
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
542 | 542 | | |
543 | 543 | | |
544 | 544 | | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
545 | 549 | | |
546 | 550 | | |
547 | 551 | | |
| |||
0 commit comments