[flang][OpenMP] Segfault in OpenMPIRBuilder::createParallel for linear() on a device target construct
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
flang segfaults compiling a `linear` clause on a combined target/simd construct.
```fortran
module m
contains
subroutine k(a, b, n)
real(8), intent(in) :: a(*)
real(8), intent(inout) :: b(*)
integer, intent(in) :: n
integer :: i, j
j = 0
!$omp target teams distribute parallel do simd linear(j)
do i = 1, n
j = j + 1
b(i) = a(i) * real(j, 8)
end do
end subroutine
end module
```
```
$ flang -fc1 -emit-llvm -fopenmp -fopenmp-is-target-device \
-triple amdgcn-amd-amdhsa -O3 -o /dev/null repro.f90
flang-24: error: unable to execute command: Segmentation fault (core dumped)
```
Deterministic: 20 crashes in 20 runs at `02c51adb8ff2`.
```
#4 llvm::CodeExtractorAnalysisCache::findSideEffectInfoForBlock(llvm::BasicBlock&)
#5 llvm::CodeExtractorAnalysisCache::CodeExtractorAnalysisCache(llvm::Function&)
#6 llvm::OpenMPIRBuilder::createParallel(...)
```
So it is in the outlining path, not the frontend.
The clause is legal on this directive — `OMP.td` lists `OMPC_Linear` in `allowedClauses` for `OMP_TargetTeamsDistributeParallelDoSimd`.
Does not reproduce with amdflang from AFAR 23.2.1 (LLVM 23) or ROCm 7.2.0 (LLVM 22), so it may be a regression in the 24 development cycle, though I have not bisected and those releases may simply handle the clause differently.
Only reproduces at `-O3`/`-emit-llvm`; `-emit-hlfir` is clean 20 out of 20, which fits the stack being in `OpenMPIRBuilder`.
This was found with the assistance of AI tools.
Contributor guide
Research direction
First reproduce the crash with the provided flang command and Fortran example, then inspect llvm::OpenMPIRBuilder::createParallel and the CodeExtractorAnalysisCache stack shown in the report. Check OMP.td for the allowed linear clause and compare the outlining path with the -emit-hlfir case; done means the target/teams/distribute/parallel/do/simd example no longer segfaults at -O3 and still emits LLVM IR.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- fortran
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100