diff --git a/src/coreclr/interpreter/compiler.cpp b/src/coreclr/interpreter/compiler.cpp index f0c58a89abc193..9289dd8eb747c5 100644 --- a/src/coreclr/interpreter/compiler.cpp +++ b/src/coreclr/interpreter/compiler.cpp @@ -6460,7 +6460,19 @@ void InterpCompiler::UpdateLocalIntervalMaps() int32_t varIndex = suspendData->returnValueVarStackOffset; if (varIndex != -1) { - suspendData->returnValueVarStackOffset = m_pVars[varIndex].offset; + assert(!m_pVars[varIndex].global); + if (m_pVars[varIndex].liveStart == m_pVars[varIndex].liveEnd) + { + // The return result of the async call is not used by the method, so the allocated + // stack offset will be immediately reused by any vars that become live. Keep the + // continuation layout unchanged, but mark the return value stack offset as invalid + // so resume skips copying the stored result back to the interpreter stack. + suspendData->returnValueVarStackOffset = -1; + } + else + { + suspendData->returnValueVarStackOffset = m_pVars[varIndex].offset; + } } } } diff --git a/src/coreclr/vm/interpexec.cpp b/src/coreclr/vm/interpexec.cpp index a8b24b9a4de456..95151d38cdfd3a 100644 --- a/src/coreclr/vm/interpexec.cpp +++ b/src/coreclr/vm/interpexec.cpp @@ -4581,7 +4581,7 @@ do \ // Explicitly copy the return value from the continuation's result storage // to the interpreter stack. - if (pAsyncSuspendData->returnValueContinuationDataSize > 0) + if (pAsyncSuspendData->returnValueVarStackOffset != -1) { memcpy(LOCAL_VAR_ADDR(pAsyncSuspendData->returnValueVarStackOffset, uint8_t), continuation->GetResultStorage(),