From ce573ac4e77ea36af82ba3608ec64932617907b3 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Fri, 16 Jan 2026 01:36:55 +0100 Subject: [PATCH] Fix assertions generated by optCreateJumpTableImpliedAssertions (default case) --- src/coreclr/jit/assertionprop.cpp | 3 +- .../JitBlue/Runtime_122254/Runtime_122254.cs | 47 +++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 src/tests/JIT/Regression/JitBlue/Runtime_122254/Runtime_122254.cs diff --git a/src/coreclr/jit/assertionprop.cpp b/src/coreclr/jit/assertionprop.cpp index 61cfb57382a612..b0744114f1c704 100644 --- a/src/coreclr/jit/assertionprop.cpp +++ b/src/coreclr/jit/assertionprop.cpp @@ -5786,7 +5786,8 @@ bool Compiler::optCreateJumpTableImpliedAssertions(BasicBlock* switchBb) // default: %name.Length is >= 8 here% // } // - if ((value > 0) && !vnStore->IsVNConstant(opVN)) + // NOTE: if offset != 0, we only know that "X + offset >= maxJumpIdx", which is not very useful. + if ((offset == 0) && (value > 0) && !vnStore->IsVNConstant(opVN)) { AssertionDsc dsc = {}; dsc.assertionKind = OAK_NOT_EQUAL; diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_122254/Runtime_122254.cs b/src/tests/JIT/Regression/JitBlue/Runtime_122254/Runtime_122254.cs new file mode 100644 index 00000000000000..4ffc71b364bcb9 --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_122254/Runtime_122254.cs @@ -0,0 +1,47 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Runtime.CompilerServices; +using Xunit; + +public class Runtime_122254 +{ + [Fact] + public static void TestEntryPoint() + { + try + { + Test(new int[0]); + } + catch (InvalidOperationException) + { + return; + } + throw new InvalidOperationException(); + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private static void Test(int[] arr) + { + int block = arr.Length; + switch (block) + { + case 2: + Console.WriteLine("2"); + break; + case 3: + Console.WriteLine("3"); + break; + case 4: + Console.WriteLine("4"); + break; + default: + if (block == 0) + { + throw new InvalidOperationException(); + } + break; + } + } +} \ No newline at end of file