From b11ba76520a8a9e1d5a86acbad87b87d3b4d5e1a Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Mon, 30 Aug 2021 13:00:53 +0200 Subject: [PATCH] Only report live ranges for allocated variables (#57843) 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 --- src/coreclr/jit/codegencommon.cpp | 9 ++-- .../JitBlue/Runtime_57767/Runtime_57767.cs | 49 +++++++++++++++++++ .../Runtime_57767/Runtime_57767.csproj | 12 +++++ 3 files changed, 66 insertions(+), 4 deletions(-) create mode 100644 src/tests/JIT/Regression/JitBlue/Runtime_57767/Runtime_57767.cs create mode 100644 src/tests/JIT/Regression/JitBlue/Runtime_57767/Runtime_57767.csproj diff --git a/src/coreclr/jit/codegencommon.cpp b/src/coreclr/jit/codegencommon.cpp index be04e20b37f7..29a4696a5662 100644 --- a/src/coreclr/jit/codegencommon.cpp +++ b/src/coreclr/jit/codegencommon.cpp @@ -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 = @@ -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()); diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_57767/Runtime_57767.cs b/src/tests/JIT/Regression/JitBlue/Runtime_57767/Runtime_57767.cs new file mode 100644 index 000000000000..b0ba821d6aab --- /dev/null +++ b/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); + } +} \ No newline at end of file diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_57767/Runtime_57767.csproj b/src/tests/JIT/Regression/JitBlue/Runtime_57767/Runtime_57767.csproj new file mode 100644 index 000000000000..f3e1cbd44b40 --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_57767/Runtime_57767.csproj @@ -0,0 +1,12 @@ + + + Exe + + + None + True + + + + +