lowering: split finally blocks for exceptional control-flow
          #55876
        
          
      
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
This change duplicates
finallyblocks in lowered IR, so that they can have a static nesting depth in thetry-catchhierarchy.Previously,
finallycontrol-flow looked like this:This kind of flow is a problem, because in a couple places the compiler assumes that it can actually "color" the CFG such that there is a static nesting depth at each BasicBlock (i.e. each BasicBlock can be labeled w/ a unique enclosing
try/catchscope). The abovefinallypattern violates that assumption.In an upcoming PR, I want to extend the lifetimes of our Event Handlers (
jl_handler_t) until the end of acatchblock (rather than the start) which noticeably breaksllvm-lower-handlers.cpp. (@Keno was very clear about this assumption in the comments for that pass.)Behaviorally this was mostly benign, except for some mis-handling of an erroring entry that turns into a non-erroring exit:
which spits out internal compiler stack traces (oops!):
That could be fixed by banning
breakandreturnwithinfinallyblocks or making the lowering more complicated, but this PR instead splits thefinallyblock into an erroring and non-erroring path so that we can attach thecatchhandler appropriately.