diff --git a/src/coreclr/jit/codegencommon.cpp b/src/coreclr/jit/codegencommon.cpp index ca15fed089034691b36a4dcbef0b26d2e76c11ca..0c660d71b52eb27f3b0c7733ad05dcea42540c27 100644 --- a/src/coreclr/jit/codegencommon.cpp +++ b/src/coreclr/jit/codegencommon.cpp @@ -6952,8 +6952,11 @@ void CodeGen::genSetScopeInfoUsingVariableRanges() end++; } - genSetScopeInfo(liveRangeIndex, start, end - start, varNum, varNum, true, loc); - liveRangeIndex++; + if (start < end) + { + genSetScopeInfo(liveRangeIndex, start, end - start, varNum, varNum, true, loc); + liveRangeIndex++; + } }; siVarLoc* curLoc = nullptr; diff --git a/src/coreclr/jit/ee_il_dll.cpp b/src/coreclr/jit/ee_il_dll.cpp index 201705ad708780da6573f7feda73a7ebc24a5ad3..b98322abe683e9ef921538ec406b52d769e4322e 100644 --- a/src/coreclr/jit/ee_il_dll.cpp +++ b/src/coreclr/jit/ee_il_dll.cpp @@ -693,9 +693,15 @@ void Compiler::eeSetLVdone() eeDispVars(info.compMethodHnd, eeVarsCount, (ICorDebugInfo::NativeVarInfo*)eeVars); } #endif // DEBUG + if ((eeVarsCount == 0) && (eeVars != nullptr)) + { + // We still call setVars with nullptr when eeVarsCount is 0 as part of the contract. + // We also need to free the nonused memory. + info.compCompHnd->freeArray(eeVars); + eeVars = nullptr; + } info.compCompHnd->setVars(info.compMethodHnd, eeVarsCount, (ICorDebugInfo::NativeVarInfo*)eeVars); - eeVars = nullptr; // We give up ownership after setVars() }