From b2ef596c415e42d79470a8356f7816aa4989e34c Mon Sep 17 00:00:00 2001 From: Bruce Forstall Date: Thu, 11 Jan 2024 13:38:20 -0800 Subject: [PATCH] Preserve debug info for merged returns 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. --- src/coreclr/jit/morph.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/coreclr/jit/morph.cpp b/src/coreclr/jit/morph.cpp index eff3d4ee413740..5e517a96c8aec3 100644 --- a/src/coreclr/jit/morph.cpp +++ b/src/coreclr/jit/morph.cpp @@ -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. @@ -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);