Skip to content

Commit

Permalink
Preserve debug info for merged returns (dotnet#96870)
Browse files Browse the repository at this point in the history
If converting a void GT_RETURN to a branch to a merged return
block, keep it as a GT_NOP if it has debug info that should
be preserved.
  • Loading branch information
BruceForstall authored and tmds committed Jan 23, 2024
1 parent b40aff7 commit 0055ad8
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/coreclr/jit/morph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14189,6 +14189,7 @@ void Compiler::fgMergeBlockReturn(BasicBlock* block)
fgAddRefPred(genReturnBB, block);
fgReturnCount--;
}

if (genReturnLocal != BAD_VAR_NUM)
{
// replace the GT_RETURN node to be a STORE_LCL_VAR that stores the return value into genReturnLocal.
Expand Down Expand Up @@ -14243,7 +14244,15 @@ void Compiler::fgMergeBlockReturn(BasicBlock* block)
noway_assert(ret->TypeGet() == TYP_VOID);
noway_assert(ret->gtGetOp1() == nullptr);

fgRemoveStmt(block, lastStmt);
if (opts.compDbgCode && lastStmt->GetDebugInfo().IsValid())
{
// We can't remove the return as it might remove a sequence point. Convert it to a NOP.
ret->gtBashToNOP();
}
else
{
fgRemoveStmt(block, lastStmt);
}
}

JITDUMP("\nUpdate " FMT_BB " to jump to common return block.\n", block->bbNum);
Expand Down

0 comments on commit 0055ad8

Please sign in to comment.