-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[release/7.0] JIT: fix bug in cloning conditions for jagged array (#8…
…3414) (#83462) Backport of #83414 to release/7.0, fixes #83242 When checking that an inner array access is in bounds, we must ensure any outer access is fully in bounds too. We were checking that `idx < array.Len` but not that `idx >= 0`. Use an unsigned compare for this check so we can do both sides with a single instruction. Fixes #83242.
- Loading branch information
1 parent
fa133ae
commit 7cd68bc
Showing
4 changed files
with
83 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/tests/JIT/Regression/JitBlue/Runtime_83242/Runtime_83242.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// 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; | ||
|
||
class Runtime_83242 | ||
{ | ||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
static int Map(int i) | ||
{ | ||
if (i == 5) return -1; | ||
return i; | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
static void Setup(int[][] a) | ||
{ | ||
for (int i = 0; i < a.Length; i++) | ||
{ | ||
a[i] = new int[5]; | ||
|
||
for (int j = 0; j < 5; j++) | ||
{ | ||
a[i][j] = j; | ||
} | ||
} | ||
} | ||
|
||
public static int Main() | ||
{ | ||
int[][] a = new int[11][]; | ||
int sum = 0; | ||
Setup(a); | ||
|
||
for (int i = 0; i < a.Length; i++) | ||
{ | ||
int ii = Map(i); | ||
|
||
// Need to ensure ii >= 0 is in the cloning | ||
// conditions for the following loop | ||
|
||
for (int j = 0; j < 5; j++) | ||
{ | ||
if (ii >= 0) | ||
{ | ||
sum += a[ii][j]; | ||
} | ||
} | ||
} | ||
|
||
Console.WriteLine($"sum is {sum}\n"); | ||
return sum; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/tests/JIT/Regression/JitBlue/Runtime_83242/Runtime_83242.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<Optimize>True</Optimize> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="$(MSBuildProjectName).cs" /> | ||
</ItemGroup> | ||
</Project> |