Skip to content

Commit

Permalink
Only report live ranges for allocated variables (#57843)
Browse files Browse the repository at this point in the history
With dead code it is possible that certain IL locals are never
allocated, but still live in other blocks. In this case there is no
information to report to the VM.

Fixes #57767
  • Loading branch information
jakobbotsch committed Aug 30, 2021
1 parent 9671726 commit b11ba76
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/coreclr/jit/codegencommon.cpp
Expand Up @@ -12199,9 +12199,9 @@ void CodeGenInterface::VariableLiveKeeper::siStartVariableLiveRange(const LclVar
{
noway_assert(varDsc != nullptr);

// Only the variables that exists in the IL, "this", and special arguments
// are reported.
if (m_Compiler->opts.compDbgInfo && varNum < m_LiveDscCount)
// Only the variables that exists in the IL, "this", and special arguments are reported, as long as they were
// allocated.
if (m_Compiler->opts.compDbgInfo && varNum < m_LiveDscCount && (varDsc->lvIsInReg() || varDsc->lvOnFrame))
{
// Build siVarLoc for this born "varDsc"
CodeGenInterface::siVarLoc varLocation =
Expand Down Expand Up @@ -12237,7 +12237,8 @@ void CodeGenInterface::VariableLiveKeeper::siEndVariableLiveRange(unsigned int v
// a valid IG so we don't report the close of a "VariableLiveRange" after code is
// emitted.

if (m_Compiler->opts.compDbgInfo && varNum < m_LiveDscCount && !m_LastBasicBlockHasBeenEmited)
if (m_Compiler->opts.compDbgInfo && varNum < m_LiveDscCount && !m_LastBasicBlockHasBeenEmited &&
m_vlrLiveDsc[varNum].hasVariableLiveRangeOpen())
{
// this variable live range is no longer valid from this point
m_vlrLiveDsc[varNum].endLiveRangeAtEmitter(m_Compiler->GetEmitter());
Expand Down
49 changes: 49 additions & 0 deletions src/tests/JIT/Regression/JitBlue/Runtime_57767/Runtime_57767.cs
@@ -0,0 +1,49 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

// Generated by Fuzzlyn v1.3 on 2021-08-19 18:34:52
// Run on .NET 6.0.0-dev on X64 Windows
// Seed: 14701429021631883067
// Reduced from 466.6 KiB to 0.7 KiB in 02:59:01
//
// Assert failure(PID 32388 [0x00007e84], Thread: 36304 [0x8dd0]): Assertion failed 'offset != BAD_STK_OFFS' in 'Program:M101(bool)' during 'Generate code' (IL size 78)
//
// File: D:\dev\dotnet\runtime\src\coreclr\jit\scopeinfo.cpp Line: 278
// Image: D:\dev\Fuzzlyn\Fuzzlyn\publish\windows-x64\Fuzzlyn.exe
//
//
public class Program
{
internal static sbyte s_4;
internal static sbyte[] s_28;
public static int Main()
{
M101(false);
return 100;
}

internal static void M101(bool arg0)
{
uint var0 = default(uint);
bool var2 = default(bool);
for (int var5 = 0; var5 < 1; var5++)
{
return;
}

for (int var9 = 0; var9 < 2; var9++)
{
for (int var10 = 0; var10 < 2; var10++)
{
var0 = (uint)var9;
s_28[0] = s_4;
if (var2)
{
arg0 = true;
}
}
}

System.Console.WriteLine(var0);
}
}
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
</PropertyGroup>
<PropertyGroup>
<DebugType>None</DebugType>
<Optimize>True</Optimize>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).cs" />
</ItemGroup>
</Project>

0 comments on commit b11ba76

Please sign in to comment.