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);