[Flang][OpenMP] Error when unstructured code is present
This is another instance where the presence of unstructured code in OpenMP regions leads to failure.
Error
error: loc("fname.f90":10:3): operation with block successors must terminate its parent block
Program
subroutine sb(ninter, numnod)
integer :: ninter, numnod
integer, dimension(:), allocatable :: indx_nm
!$omp parallel
if (ninter>0) then
allocate( indx_nm(numnod) )
endif
220 continue
goto 220
!$omp end parallel
end subroutine
There is the problem:
"omp.parallel"() <{operandSegmentSizes = array<i32: 0, 0, 0, 0, 0>}> ({
[...]
"cf.br"()[^bb1] : () -> ()
^bb1: // 2 preds: ^bb0, ^bb1
"cf.br"()[^bb1] : () -> () // <-- not terminating the block
"omp.terminator"() : () -> ()
}) : () -> ()
This happens because we always insert a terminator into the last block of the construct. In this case the last block is the loop (which is lowered later, and inserts its own branch), and we end up with omp.terminator and cf.br in the same block.
This looks like it would be solved by the recursive lowering, since the loop would be lowered as a part of the parallel op lowering. This would make it possible to only insert omp.terminator where there isn't one already. I'll try to have a prototype of that working soon.
Thanks @kparzysz for investigating this. It will be great if it works with your proposal.
It might be good to go back and have a look at some of the previous fixes to ensure that you have the full context. https://github.com/flang-compiler/f18-llvm-project/pull/1178 https://github.com/flang-compiler/f18-llvm-project/pull/1394
@llvm/issue-subscribers-flang-ir
Author: Kiran Chandramohan (kiranchandramohan)
Error
error: loc("fname.f90":10:3): operation with block successors must terminate its parent block
Program
subroutine sb(ninter, numnod)
integer :: ninter, numnod
integer, dimension(:), allocatable :: indx_nm
!$omp parallel
if (ninter>0) then
allocate( indx_nm(numnod) )
endif
220 continue
goto 220
!$omp end parallel
end subroutine