[flang-commits] [flang] [flang][Lower] Emit exiting branches from within constructs (PR #92455)

Krzysztof Parzyszek via flang-commits flang-commits at lists.llvm.org
Fri May 17 16:04:20 PDT 2024


kparzysz wrote:

The previous fix failed for unstructured flow because it assumed that every evaluation that ends a block also exits the construct. 
The updated code recognizes evaluations that end a block (within a construct) because their lexical successor is a target of some branch.

However, I think this can be fixed in a more elegant way.  Below is the PFT for the most recent problematic subroutine:
```
1 Subroutine s: subroutine s(j, k)
  1 ComputedGotoStmt! -> 9: goto(11, 22, 33) j-3
  <<IfConstruct!>> -> 10
    2 ^IfStmt [negate] -> 10: if(j == 2) goto 22
    <<IfConstruct>> -> 9
      5 ^IfStmt [negate] -> 9: if(j == 1) goto 11
      8 ^AssignmentStmt: k = k + 1
      7 EndIfStmt
    <<End IfConstruct>>
    9 ^AssignmentStmt!: 11 k = k + 10
    4 EndIfStmt
  <<End IfConstruct!>>
  10 ^AssignmentStmt: 22 k = k + 100
  11 ^AssignmentStmt: 33 k = k + 1000
  12 EndSubroutineStmt: end
End Subroutine s
```
The outermost `IfConstruct` has a branch going from outside of it (the computed goto), to the assignment at index 9.  If this was a Fortran program, this would not be allowed, and this additional patch would not have been necessary.

I think that a better fix would be to avoid creating such constructs in the PFT, if they didn't exist in the source.  What do you think?

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


More information about the flang-commits mailing list