From aeccef92c999fb3e2bd98e6817fe4dfe25e7347c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 17 Jun 2026 14:58:31 +0000 Subject: [PATCH 1/4] Initial plan From 95237f577bd28c9992c826fea2eb62c96ead8b2d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 17 Jun 2026 15:02:45 +0000 Subject: [PATCH 2/4] JIT: Reset compGenTreeID on failed Materialize to avoid leaking gen tree IDs Co-authored-by: jakobbotsch <7887810+jakobbotsch@users.noreply.github.com> --- src/coreclr/jit/scev.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/coreclr/jit/scev.cpp b/src/coreclr/jit/scev.cpp index 503f06b785e729..7f8f0cc1e34503 100644 --- a/src/coreclr/jit/scev.cpp +++ b/src/coreclr/jit/scev.cpp @@ -1451,7 +1451,18 @@ GenTree* ScalarEvolutionContext::Materialize(Scev* scev) { ValueNumPair vnp; GenTree* result; - return Materialize(scev, true, &result, &vnp) ? result : nullptr; + + // Materializing IR may create nodes before failing partway through (e.g. + // when a subexpression cannot be materialized). Snapshot the gen tree ID so + // that we can roll it back and avoid leaking IDs for the orphaned nodes. + unsigned prevGenTreeID = m_compiler->compGenTreeID; + if (Materialize(scev, true, &result, &vnp)) + { + return result; + } + + m_compiler->compGenTreeID = prevGenTreeID; + return nullptr; } //------------------------------------------------------------------------ From 61314aebc8b126e623e90b75097dbb722dd83424 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 17 Jun 2026 15:15:47 +0000 Subject: [PATCH 3/4] JIT: Guard compGenTreeID reset with INDEBUG since the field is DEBUG-only Co-authored-by: jakobbotsch <7887810+jakobbotsch@users.noreply.github.com> --- src/coreclr/jit/scev.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/coreclr/jit/scev.cpp b/src/coreclr/jit/scev.cpp index 7f8f0cc1e34503..d2f47b71356566 100644 --- a/src/coreclr/jit/scev.cpp +++ b/src/coreclr/jit/scev.cpp @@ -1455,13 +1455,13 @@ GenTree* ScalarEvolutionContext::Materialize(Scev* scev) // Materializing IR may create nodes before failing partway through (e.g. // when a subexpression cannot be materialized). Snapshot the gen tree ID so // that we can roll it back and avoid leaking IDs for the orphaned nodes. - unsigned prevGenTreeID = m_compiler->compGenTreeID; + INDEBUG(unsigned prevGenTreeID = m_compiler->compGenTreeID); if (Materialize(scev, true, &result, &vnp)) { return result; } - m_compiler->compGenTreeID = prevGenTreeID; + INDEBUG(m_compiler->compGenTreeID = prevGenTreeID); return nullptr; } From 8975decf79fee7a5c93cd37a1c96053bfceaeb0f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 17 Jun 2026 16:10:20 +0000 Subject: [PATCH 4/4] JIT tests: add Runtime_129527 regression to merged Regression_ro_2 Co-authored-by: jakobbotsch <7887810+jakobbotsch@users.noreply.github.com> --- .../JitBlue/Runtime_129527/Runtime_129527.cs | 69 +++++++++++++++++++ .../JIT/Regression/Regression_ro_2.csproj | 1 + 2 files changed, 70 insertions(+) create mode 100644 src/tests/JIT/Regression/JitBlue/Runtime_129527/Runtime_129527.cs diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_129527/Runtime_129527.cs b/src/tests/JIT/Regression/JitBlue/Runtime_129527/Runtime_129527.cs new file mode 100644 index 00000000000000..f200938147107f --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_129527/Runtime_129527.cs @@ -0,0 +1,69 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace Runtime_129527; + +using System.Runtime.Intrinsics.Arm; +using System.Threading.Tasks; +using Xunit; + +public struct S1 +{ + public long F3; +} + +public interface IRuntime +{ + void WriteLine(string site, T value); +} + +public sealed class Runtime : IRuntime +{ + public void WriteLine(string site, T value) + { + } +} + +public static class Runtime_129527 +{ + private static IRuntime s_rt = new Runtime(); + private static bool[] s_8 = new bool[1]; + private static long s_13; + + [Fact] + public static int TestEntryPoint() + { + M0(); + return s_13 == 0 ? 100 : 101; + } + + private static void M0() + { + uint var9 = default; + S1[] var24 = new S1[1]; + ulong var34 = default; + try + { + var9 = 1; + s_8[0] |= false; + } + catch + { + } + + for (int lvar31 = -2147483646; lvar31 > -2147483648; lvar31--) + { + ulong vr0 = (ulong)(lvar31 - var9++); + short var33 = Crc32.Arm64.IsSupported ? (short)Crc32.Arm64.ComputeCrc32C(0, vr0) : (short)vr0; + s_13 = var24[0].F3; + M6().GetAwaiter().GetResult(); + s_rt.WriteLine("c_122", var34); + s_rt.WriteLine("c_126", var33); + } + } + + private static async Task M6() + { + await Task.Yield(); + } +} diff --git a/src/tests/JIT/Regression/Regression_ro_2.csproj b/src/tests/JIT/Regression/Regression_ro_2.csproj index bba2c75d0bcd0e..0731ca82916aa8 100644 --- a/src/tests/JIT/Regression/Regression_ro_2.csproj +++ b/src/tests/JIT/Regression/Regression_ro_2.csproj @@ -102,6 +102,7 @@ +