[flang-commits] [flang] [flang] Generate valid IR on GOTO DO body (PR #66084)
via flang-commits
flang-commits at lists.llvm.org
Tue Sep 12 20:27:38 PDT 2023
vdonaldson wrote:
The problem isn't restricted to stride computations. Other loop control expressions are also problematic.
```
subroutine sub(j)
integer :: i, j
if (j .eq. 2) goto 70
do i = 1, 2
70 j = j + 1
end do
end
```
```
$ flang blah.f90
./blah.f90:3:3: warning: Label '70' is in a construct that should not be used as a branch target here
if (j .eq. 2) goto 70
^^^^^^^^^^^^^^^^^^^^^
error: loc("blah.f90":5:5): operand #1 does not dominate this use
mlir did not succeed
```
This is nonconformant code. f90 Clause 8.1.1.2 states: _Transfer of control to the interior of a block from outside the block is prohibited._ f18 Clause 11.1.2.1 has the same program restriction with a minor qualification.
Some compilers flag this as a hard error, which is one possibility. A question there is whether to generate errors for all branches into blocks, or allow some that are more likely to be benign.
Otherwise, the primary goal is to avoid a compiler crash and generate an executable that will likely crash at runtime. It might be possible to generalize this PR to do that, but at a cost of generating somewhat more complex code that isn't needed most of the time.
At this point I don't have a concrete recommendation.
https://github.com/llvm/llvm-project/pull/66084
More information about the flang-commits
mailing list