Skip to content

Commit 335e2d3

Browse files
committed
Fix BBJ_EHFILTERRET handling in fgRemoveBlockAsPred
fgRemoveBlockAsPred had special handling to not decrease the bbRefs count of the filter-handler targeted by BBJ_EHFILTERRET. This is incorrect, as the filter-handler already has an extra "beginning of handler" extra ref count. Possibly this code was never invoked before as filters were not previously removed. Also, fix the JitDump output of the filter ret block in block dumps.
1 parent 41953b7 commit 335e2d3

File tree

6 files changed

+13
-9
lines changed

6 files changed

+13
-9
lines changed

src/coreclr/jit/block.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ void BasicBlock::dspJumpKind()
637637
break;
638638

639639
case BBJ_EHFILTERRET:
640-
printf(" (fltret)");
640+
printf(" -> " FMT_BB " (fltret)", bbJumpDest->bbNum);
641641
break;
642642

643643
case BBJ_EHCATCHRET:

src/coreclr/jit/clrjit.natvis

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Documentation for VS debugger format specifiers: https://docs.microsoft.com/en-u
2121
</Type>
2222

2323
<Type Name="BasicBlock">
24-
<DisplayString Condition="bbJumpKind==BBJ_COND || bbJumpKind==BBJ_ALWAYS || bbJumpKind==BBJ_LEAVE || bbJumpKind==BBJ_EHCATCHRET || bbJumpKind==BBJ_CALLFINALLY">BB{bbNum,d}->BB{bbJumpDest->bbNum,d}; {bbJumpKind,en}</DisplayString>
24+
<DisplayString Condition="bbJumpKind==BBJ_COND || bbJumpKind==BBJ_ALWAYS || bbJumpKind==BBJ_LEAVE || bbJumpKind==BBJ_EHCATCHRET || bbJumpKind==BBJ_CALLFINALLY || bbJumpKind==BBJ_EHFILTERRET">BB{bbNum,d}->BB{bbJumpDest->bbNum,d}; {bbJumpKind,en}</DisplayString>
2525
<DisplayString Condition="bbJumpKind==BBJ_SWITCH">BB{bbNum,d}; {bbJumpKind,en}; {bbJumpSwt->bbsCount} cases</DisplayString>
2626
<DisplayString Condition="bbJumpKind==BBJ_EHFINALLYRET">BB{bbNum,d}; {bbJumpKind,en}; {bbJumpEhf->bbeCount} succs</DisplayString>
2727
<DisplayString>BB{bbNum,d}; {bbJumpKind,en}</DisplayString>

src/coreclr/jit/fgbasic.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ bool Compiler::fgEnsureFirstBBisScratch()
268268
}
269269

270270
// The first block has an implicit ref count which we must
271-
// remove. Note the ref count could be greater that one, if
271+
// remove. Note the ref count could be greater than one, if
272272
// the first block is not scratch and is targeted by a
273273
// branch.
274274
assert(fgFirstBB->bbRefs >= 1);

src/coreclr/jit/fgdiagnostic.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2077,7 +2077,8 @@ void Compiler::fgTableDispBasicBlock(BasicBlock* block, int ibcColWidth /* = 0 *
20772077
break;
20782078

20792079
case BBJ_EHFILTERRET:
2080-
printf("%*s (fltret)", maxBlockNumWidth - 2, "");
2080+
printf("-> " FMT_BB "%*s (fltret)", block->GetJumpDest()->bbNum,
2081+
maxBlockNumWidth - max(CountDigits(block->GetJumpDest()->bbNum), 2), "");
20812082
break;
20822083

20832084
case BBJ_EHCATCHRET:

src/coreclr/jit/fgflow.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ void Compiler::fgRemoveBlockAsPred(BasicBlock* block)
346346
case BBJ_CALLFINALLY:
347347
case BBJ_ALWAYS:
348348
case BBJ_EHCATCHRET:
349+
case BBJ_EHFILTERRET:
349350
fgRemoveRefPred(block->GetJumpDest(), block);
350351
break;
351352

@@ -358,11 +359,6 @@ void Compiler::fgRemoveBlockAsPred(BasicBlock* block)
358359
fgRemoveRefPred(block->Next(), block);
359360
break;
360361

361-
case BBJ_EHFILTERRET:
362-
block->GetJumpDest()->bbRefs++; // To compensate the bbRefs-- inside fgRemoveRefPred
363-
fgRemoveRefPred(block->GetJumpDest(), block);
364-
break;
365-
366362
case BBJ_EHFINALLYRET:
367363
for (BasicBlock* const succ : block->EHFinallyRetSuccs())
368364
{

src/coreclr/jit/fgopt.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,11 @@ bool Compiler::fgRemoveUnreachableBlocks(CanRemoveBlockBody canRemoveBlock)
437437
// to properly set the info.compProfilerCallback flag.
438438
continue;
439439
}
440+
else if ((block->bbFlags & BBF_DONT_REMOVE) && block->isEmpty() && block->KindIs(BBJ_THROW))
441+
{
442+
// We already converted a non-removable block to a throw; don't bother processing it again.
443+
continue;
444+
}
440445
else if (!canRemoveBlock(block))
441446
{
442447
continue;
@@ -458,6 +463,8 @@ bool Compiler::fgRemoveUnreachableBlocks(CanRemoveBlockBody canRemoveBlock)
458463

459464
// Unmark the block as removed, clear BBF_INTERNAL, and set BBJ_IMPORTED
460465

466+
JITDUMP("Converting BBF_DONT_REMOVE block " FMT_BB " to BBJ_THROW\n", block->bbNum);
467+
461468
// The successors may be unreachable after this change.
462469
changed |= block->NumSucc() > 0;
463470

0 commit comments

Comments
 (0)