Skip to content

Commit

Permalink
Consider finally that jumps to itself as non-empty (dotnet#58771)
Browse files Browse the repository at this point in the history
* decrement the reference of unreachable finally

* Proper fix
  • Loading branch information
kunalspathak authored Sep 9, 2021
1 parent b7ac52b commit a09d088
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/coreclr/jit/fgehopt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ PhaseStatus Compiler::fgRemoveEmptyFinally()
continue;
}

// If the finally's block jumps back to itself, then it is not empty.
if ((firstBlock->bbJumpKind == BBJ_ALWAYS) && firstBlock->bbJumpDest == firstBlock)
{
JITDUMP("EH#%u finally has basic block that jumps to itself; skipping.\n", XTnum);
XTnum++;
continue;
}

// Limit for now to finallys that contain only a GT_RETFILT.
bool isEmpty = true;

Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/jit/jiteh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4410,7 +4410,7 @@ void Compiler::fgExtendEHRegionBefore(BasicBlock* block)
#endif // DEBUG

// The first block of a handler has an artificial extra refcount. Transfer that to the new block.
assert(block->bbRefs > 0);
noway_assert(block->countOfInEdges() > 0);
block->bbRefs--;

HBtab->ebdHndBeg = bPrev;
Expand Down Expand Up @@ -4459,7 +4459,7 @@ void Compiler::fgExtendEHRegionBefore(BasicBlock* block)
#endif // DEBUG

// The first block of a filter has an artificial extra refcount. Transfer that to the new block.
assert(block->bbRefs > 0);
noway_assert(block->countOfInEdges() > 0);
block->bbRefs--;

HBtab->ebdFilter = bPrev;
Expand Down

0 comments on commit a09d088

Please sign in to comment.