diff --git a/src/jit/rangecheck.cpp b/src/jit/rangecheck.cpp index 96fcaf9561ec..5c260878640e 100644 --- a/src/jit/rangecheck.cpp +++ b/src/jit/rangecheck.cpp @@ -362,7 +362,7 @@ bool RangeCheck::IsMonotonicallyIncreasing(GenTree* expr, bool rejectNegativeCon JITDUMP("[RangeCheck::IsMonotonicallyIncreasing] [%06d]\n", Compiler::dspTreeID(expr)); // Add hashtable entry for expr. - bool alreadyPresent = !m_pSearchPath->Set(expr, nullptr, SearchPath::Overwrite); + bool alreadyPresent = m_pSearchPath->Set(expr, nullptr, SearchPath::Overwrite); if (alreadyPresent) { return true; diff --git a/tests/src/JIT/Regression/JitBlue/Runtime_1104/Runtime_1104.cs b/tests/src/JIT/Regression/JitBlue/Runtime_1104/Runtime_1104.cs new file mode 100644 index 000000000000..da0de8fadfa2 --- /dev/null +++ b/tests/src/JIT/Regression/JitBlue/Runtime_1104/Runtime_1104.cs @@ -0,0 +1,62 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Diagnostics; +using System.Runtime.CompilerServices; + +class Runtime_1104 +{ + static int TestOutOfBoundProxy(Func actualTest) + { + try + { + actualTest(); + } + catch (IndexOutOfRangeException) + { + Console.WriteLine("caught IndexOutOfRangeException"); + return 100; + } + Debug.Fail("unreached"); + return 101; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + static int TestOutOfBoundLowerDecreasing() + { + int[] arr = new int[10]; + int i = 9; + int j = 15; + int sum = 0; + + // our range check optimizer is very naive, so if you don't have + // i < 10, then it thinks `i` can overflow and doesn't bother + // calling `Widen` at all. + // + while (j >= 0 && i < 10) + { + --j; + --i; + sum += arr[i]; // range check will use 9 as lower bound. + + Console.WriteLine("i = " + i + ", j = " + j); + } + return sum; + } + + public static int Main() + { + try + { + TestOutOfBoundProxy(TestOutOfBoundLowerDecreasing); + } + catch (Exception) + { + return 101; + } + + return 100; + } +} diff --git a/tests/src/JIT/Regression/JitBlue/Runtime_1104/Runtime_1104.csproj b/tests/src/JIT/Regression/JitBlue/Runtime_1104/Runtime_1104.csproj new file mode 100644 index 000000000000..95052d9884f1 --- /dev/null +++ b/tests/src/JIT/Regression/JitBlue/Runtime_1104/Runtime_1104.csproj @@ -0,0 +1,33 @@ + + + + + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + Exe + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + ..\..\ + + + + + + + False + + + + None + True + + + + + + + + + +