Skip to content

Commit 6ea79a1

Browse files
authored
Fix Issue 1104 (dotnet#1734)
* Fix the incorrect change where 'alreadyPresent' was incorrectly initialized. The PR that introduced this issue: dotnet/coreclr#23109 * Add test case
1 parent ac68cde commit 6ea79a1

File tree

3 files changed

+73
-1
lines changed

3 files changed

+73
-1
lines changed

src/coreclr/src/jit/rangecheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ bool RangeCheck::IsMonotonicallyIncreasing(GenTree* expr, bool rejectNegativeCon
362362
JITDUMP("[RangeCheck::IsMonotonicallyIncreasing] [%06d]\n", Compiler::dspTreeID(expr));
363363

364364
// Add hashtable entry for expr.
365-
bool alreadyPresent = !m_pSearchPath->Set(expr, nullptr, SearchPath::Overwrite);
365+
bool alreadyPresent = m_pSearchPath->Set(expr, nullptr, SearchPath::Overwrite);
366366
if (alreadyPresent)
367367
{
368368
return true;
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using System.Diagnostics;
7+
using System.Runtime.CompilerServices;
8+
9+
class Runtime_1104
10+
{
11+
static int TestOutOfBoundProxy(Func<int> actualTest)
12+
{
13+
try
14+
{
15+
actualTest();
16+
}
17+
catch (IndexOutOfRangeException)
18+
{
19+
Console.WriteLine("caught IndexOutOfRangeException");
20+
return 100;
21+
}
22+
Debug.Fail("unreached");
23+
return 101;
24+
}
25+
26+
[MethodImpl(MethodImplOptions.NoInlining)]
27+
static int TestOutOfBoundLowerDecreasing()
28+
{
29+
int[] arr = new int[10];
30+
int i = 9;
31+
int j = 15;
32+
int sum = 0;
33+
34+
// our range check optimizer is very naive, so if you don't have
35+
// i < 10, then it thinks `i` can overflow and doesn't bother
36+
// calling `Widen` at all.
37+
//
38+
while (j >= 0 && i < 10)
39+
{
40+
--j;
41+
--i;
42+
sum += arr[i]; // range check will use 9 as lower bound.
43+
44+
Console.WriteLine("i = " + i + ", j = " + j);
45+
}
46+
return sum;
47+
}
48+
49+
public static int Main()
50+
{
51+
try
52+
{
53+
TestOutOfBoundProxy(TestOutOfBoundLowerDecreasing);
54+
}
55+
catch (Exception)
56+
{
57+
return 101;
58+
}
59+
60+
return 100;
61+
}
62+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>Exe</OutputType>
4+
<DebugType>None</DebugType>
5+
<Optimize>True</Optimize>
6+
</PropertyGroup>
7+
<ItemGroup>
8+
<Compile Include="$(MSBuildProjectName).cs" />
9+
</ItemGroup>
10+
</Project>

0 commit comments

Comments
 (0)