[flang-commits] [flang] [flang] Generate valid IR on GOTO DO body (PR #66084)

via flang-commits flang-commits at lists.llvm.org
Tue Sep 19 16:11:05 PDT 2023


vdonaldson wrote:

@luporl After yet more research into Fortran standards and legacy code we've come to the conclusion that it is best to go ahead with the code in this PR after all.

Additional detail:

I had thought that f77 allowed branching into a loop, and it was first prohibited in f90. However, the f77 standard has an appendix section A2 _Conflicts with ANSI 3.9-1966_ that lists conflicts between f66 and f77. Item (7) in the list is:

_This standard does not permit a transfer of control into the range of a DO-loop from outside the range. The range of a DO-loop may be entered only by the execution of a DO statement. ANSI X3.9-1966 permitted transfer of control into the range of a DO-loop under certain conditions. This involved the concept referred to as "extended range of a DO."_

See also f77 Clause 11.10 _DO Statement_, especially 11.10.1 _Range of a DO-Loop_ and 11.10.2 _Active and Inactive DO_Loops_.

So the prohibition against branching into a loop dates back to f77, and only f66 allows it. But f66 apparently did in fact explicitly allow it.

Despite the prohibition starting with f77 and the fact that executing such a branch will typically cause a crash or other bad behavior, enough compilers allow these f66 branches for rare legacy cases that it may be best to support it with the existing warning.

So please go ahead with the push. If someone eventually finds a case where doing this has negative consequences, such as an executable performance cost in a more general use case, we can revisit the issue at that time.

Thanks for working on this.

https://github.com/llvm/llvm-project/pull/66084


More information about the flang-commits mailing list