JIT: Fix handling of filter successors (#89275)
authorJakob Botsch Nielsen <Jakob.botsch.nielsen@gmail.com>
Fri, 21 Jul 2023 20:04:58 +0000 (22:04 +0200)
committerGitHub <noreply@github.com>
Fri, 21 Jul 2023 20:04:58 +0000 (22:04 +0200)
commit18024f42ac29d9d2ea4a5a343e2fb5ddaf8fd51a
tree5875e43329721632a4d9032f495fbe12372234f5
parentacaedac8a7b7faf1d596b265cad7bbc68e6eff31
JIT: Fix handling of filter successors (#89275)

Filters are run during the first pass of EH which makes determining
their successors complicated, and the JIT did not get this right.  In
particular, after running filters as part of first-pass EH, control may
flow to any enclosed finally or fault handler as part of second-pass EH.
Thus, these should be considered as EH successors. This adds a
BasicBlock::VisitEHSecondPassSuccs to visit these successors.

The logic was mostly extracted from liveness that (almost) got it right:
there was a condition that meant the logic did not run for top-level
try-filter clauses. This change folds in Bruce's change to fix this
scenario as well.

There was one more bug in the logic in liveness: to determine the
enclosed fault/finally blocks, the logic iterates backwards in the EH
table while looking for enclosed clauses. However, this was only
checking for clauses enclosed in the try region when it should also
check for clauses enclosed in the handler region.

Fix #86538
Fix #88168

Co-authored-by: Bruce Forstall <brucefo@microsoft.com>
12 files changed:
src/coreclr/jit/block.cpp
src/coreclr/jit/block.h
src/coreclr/jit/compiler.h
src/coreclr/jit/compiler.hpp
src/coreclr/jit/jiteh.cpp
src/coreclr/jit/liveness.cpp
src/coreclr/jit/lsra.cpp
src/coreclr/jit/promotionliveness.cpp
src/tests/JIT/Regression/JitBlue/Runtime_86538/Runtime_86538.cs [new file with mode: 0644]
src/tests/JIT/Regression/JitBlue/Runtime_86538/Runtime_86538.csproj [new file with mode: 0644]
src/tests/JIT/Regression/JitBlue/Runtime_88168/Runtime_88168.cs [new file with mode: 0644]
src/tests/JIT/Regression/JitBlue/Runtime_88168/Runtime_88168.csproj [new file with mode: 0644]