<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/91526>91526</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[Flang][OpenMP][OpenACC] Another unstructured code interaction issue
</td>
</tr>
<tr>
<th>Labels</th>
<td>
flang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
kiranchandramohan
</td>
</tr>
</table>
<pre>
In a special case where there is an OpenMP construct in the `if` case and unstructured code in the `else` case, an incorrect branch is generated from the `if` code to the `else` code.
```
subroutine simple(y)
implicit none
logical, intent(in) :: y
integer :: i
if (y) then
!$omp parallel
i = 1
!$omp end parallel
else
stop 1
end if
end subroutine simple
```
In the following HLFIR code that is generated, there is an incorrect branch `cf.br ^bb2`.
```
cf.cond_br %4, ^bb1, ^bb2
^bb1: // pred: ^bb0
omp.parallel {
%c1_i32_1 = arith.constant 1 : i32
hlfir.assign %c1_i32_1 to %1#0 : i32, !fir.ref<i32>
omp.terminator
}
cf.br ^bb2
^bb2: // 2 preds: ^bb0, ^bb1
%c1_i32 = arith.constant 1 : i32
%false = arith.constant false
%false_0 = arith.constant false
%5 = fir.call @_FortranAStopStatement(%c1_i32, %false, %false_0) fastmath<contract> : (i32, i1, i1) -> none
fir.unreachable
```
The correct branch should be generated for this case in https://github.com/llvm/llvm-project/blob/e3938f4d71493673033f6190454e7e19d5411ea7/flang/lib/Lower/Bridge.cpp#L4547. But this code is not entered since the lexical successor of the OpenMP construct evaluation is the first evaluation inside the OpenMP construct. Comparing with similar code like the `block` construct, there is an `end Block` evaluation that has the successor marked correctly.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVc2O4zYMfhrlQqxhy3YcH3LIzwYdYIoW3d4DWaJjdWTJkOSdztsXku2JZyaHLRA4EsmP-khKJHNO3jTinpRHUp43bPSdsfsXaZnmHdPCst50TG8aI972TxoYuAG5ZAo4cwivHVoEH7_SAd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