Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 04d3f0d

Browse files
authored
Port the 5.0 fix for issue #1104 (#28003)
* Port the 5.0 fix for issue #1104 3.1 - Pull Request Runtime\#1734 - This change corrects a cut-and paste typo with a previous commit. - Includes test case Runtime_1104.cs * Updated the csproj to use 3.1 syntax
1 parent 0656e62 commit 04d3f0d

File tree

3 files changed

+96
-1
lines changed

3 files changed

+96
-1
lines changed

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: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<SchemaVersion>2.0</SchemaVersion>
8+
<ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
9+
<OutputType>Exe</OutputType>
10+
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
11+
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
12+
</PropertyGroup>
13+
<!-- Default configurations to help VS understand the configurations -->
14+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "></PropertyGroup>
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' " />
16+
<ItemGroup>
17+
<CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
18+
<Visible>False</Visible>
19+
</CodeAnalysisDependentAssemblyPaths>
20+
</ItemGroup>
21+
<PropertyGroup>
22+
<DebugType>None</DebugType>
23+
<Optimize>True</Optimize>
24+
</PropertyGroup>
25+
<ItemGroup>
26+
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
27+
</ItemGroup>
28+
<ItemGroup>
29+
<Compile Include="$(MSBuildProjectName).cs" />
30+
</ItemGroup>
31+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
32+
<PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "></PropertyGroup>
33+
</Project>

0 commit comments

Comments
 (0)