Skip to content

Commit eafcb9a

Browse files
BruceForstalltmds
authored andcommitted
Fix maintenance of genReturnBB pointer (dotnet#96935)
If the `genReturnBB` block is split, the pointer needs to be updated. Without this, we ended up with a situation where the `genReturnBB` did not point to the return block, leading to omitting the code to remove the PInvoke frame from the thread's Frame list. Fixes dotnet#96409
1 parent 8636874 commit eafcb9a

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

src/coreclr/jit/compiler.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5348,6 +5348,8 @@ class Compiler
53485348
IL_OFFSET fgFindBlockILOffset(BasicBlock* block);
53495349
void fgFixEntryFlowForOSR();
53505350

5351+
void fgUpdateSingleReturnBlock(BasicBlock* block);
5352+
53515353
BasicBlock* fgSplitBlockAtBeginning(BasicBlock* curr);
53525354
BasicBlock* fgSplitBlockAtEnd(BasicBlock* curr);
53535355
BasicBlock* fgSplitBlockAfterStatement(BasicBlock* curr, Statement* stmt);

src/coreclr/jit/fgbasic.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4755,6 +4755,24 @@ IL_OFFSET Compiler::fgFindBlockILOffset(BasicBlock* block)
47554755
return BAD_IL_OFFSET;
47564756
}
47574757

4758+
//------------------------------------------------------------------------------
4759+
// fgUpdateSingleReturnBlock : A block has been split. If it was the single return
4760+
// block, then update the single return block pointer.
4761+
//
4762+
// Arguments:
4763+
// block - The block that was split
4764+
//
4765+
void Compiler::fgUpdateSingleReturnBlock(BasicBlock* block)
4766+
{
4767+
assert(block->KindIs(BBJ_ALWAYS));
4768+
if (genReturnBB == block)
4769+
{
4770+
assert(block->GetTarget()->KindIs(BBJ_RETURN));
4771+
JITDUMP("Updating genReturnBB from " FMT_BB " to " FMT_BB "\n", block->bbNum, block->GetTarget()->bbNum);
4772+
genReturnBB = block->GetTarget();
4773+
}
4774+
}
4775+
47584776
//------------------------------------------------------------------------------
47594777
// fgSplitBlockAtEnd - split the given block into two blocks.
47604778
// All code in the block stays in the original block.
@@ -4831,6 +4849,8 @@ BasicBlock* Compiler::fgSplitBlockAtEnd(BasicBlock* curr)
48314849

48324850
fgAddRefPred(newBlock, curr);
48334851

4852+
fgUpdateSingleReturnBlock(curr);
4853+
48344854
return newBlock;
48354855
}
48364856

src/coreclr/jit/fgdiagnostic.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2255,6 +2255,12 @@ void Compiler::fgTableDispBasicBlock(BasicBlock* block, int ibcColWidth /* = 0 *
22552255
}
22562256
}
22572257

2258+
// Indicate if it's the single return block
2259+
if (block == genReturnBB)
2260+
{
2261+
printf(" one-return");
2262+
}
2263+
22582264
printf("\n");
22592265
}
22602266

@@ -3186,6 +3192,7 @@ void Compiler::fgDebugCheckBBlist(bool checkBBNum /* = false */, bool checkBBRef
31863192
if (genReturnBB != nullptr)
31873193
{
31883194
assert(genReturnBB->GetFirstLIRNode() != nullptr || genReturnBB->bbStmtList != nullptr);
3195+
assert(genReturnBB->KindIs(BBJ_RETURN));
31893196
}
31903197

31913198
// If this is an inlinee, we're done checking.

0 commit comments

Comments
 (0)