Skip to content

Commit

Permalink
Fix maintenance of genReturnBB pointer (#96935)
Browse files Browse the repository at this point in the history
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 #96409
  • Loading branch information
BruceForstall authored Jan 18, 2024
1 parent a7b63ae commit 02a3fcb
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -5348,6 +5348,8 @@ class Compiler
IL_OFFSET fgFindBlockILOffset(BasicBlock* block);
void fgFixEntryFlowForOSR();

void fgUpdateSingleReturnBlock(BasicBlock* block);

BasicBlock* fgSplitBlockAtBeginning(BasicBlock* curr);
BasicBlock* fgSplitBlockAtEnd(BasicBlock* curr);
BasicBlock* fgSplitBlockAfterStatement(BasicBlock* curr, Statement* stmt);
Expand Down
20 changes: 20 additions & 0 deletions src/coreclr/jit/fgbasic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4755,6 +4755,24 @@ IL_OFFSET Compiler::fgFindBlockILOffset(BasicBlock* block)
return BAD_IL_OFFSET;
}

//------------------------------------------------------------------------------
// fgUpdateSingleReturnBlock : A block has been split. If it was the single return
// block, then update the single return block pointer.
//
// Arguments:
// block - The block that was split
//
void Compiler::fgUpdateSingleReturnBlock(BasicBlock* block)
{
assert(block->KindIs(BBJ_ALWAYS));
if (genReturnBB == block)
{
assert(block->GetTarget()->KindIs(BBJ_RETURN));
JITDUMP("Updating genReturnBB from " FMT_BB " to " FMT_BB "\n", block->bbNum, block->GetTarget()->bbNum);
genReturnBB = block->GetTarget();
}
}

//------------------------------------------------------------------------------
// fgSplitBlockAtEnd - split the given block into two blocks.
// All code in the block stays in the original block.
Expand Down Expand Up @@ -4831,6 +4849,8 @@ BasicBlock* Compiler::fgSplitBlockAtEnd(BasicBlock* curr)

fgAddRefPred(newBlock, curr);

fgUpdateSingleReturnBlock(curr);

return newBlock;
}

Expand Down
7 changes: 7 additions & 0 deletions src/coreclr/jit/fgdiagnostic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2255,6 +2255,12 @@ void Compiler::fgTableDispBasicBlock(BasicBlock* block, int ibcColWidth /* = 0 *
}
}

// Indicate if it's the single return block
if (block == genReturnBB)
{
printf(" one-return");
}

printf("\n");
}

Expand Down Expand Up @@ -3186,6 +3192,7 @@ void Compiler::fgDebugCheckBBlist(bool checkBBNum /* = false */, bool checkBBRef
if (genReturnBB != nullptr)
{
assert(genReturnBB->GetFirstLIRNode() != nullptr || genReturnBB->bbStmtList != nullptr);
assert(genReturnBB->KindIs(BBJ_RETURN));
}

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

0 comments on commit 02a3fcb

Please sign in to comment.