Repository navigation
JIT: Fix several range check correctness bugs #134466
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
df26e50
JIT: Fix RangeOps::ShiftRight for logical shifts of possibly negative…
EgorBo 54eeff4
JIT: Don't compute integer ranges for floating point VNs in range check
EgorBo 86c0002
JIT: Don't skip def overflow checks for dependent ranges in range check
EgorBo 015c033
JIT: ARM64: Honor contained index extension in genLeaInstruction
EgorBo 2083ddf
Skip Runtime_134452 on Mono
EgorBo 69c3d3b
Merge latest main into jit-bounds-check-fixes
EgorBo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,33 @@ | ||
| // 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_134451 | ||
| { | ||
| [Fact] | ||
| public static void TestEntryPoint() | ||
| { | ||
| Assert.Throws<IndexOutOfRangeException>(() => Test(new int[101], true)); | ||
| } | ||
|
|
||
| // "x" wraps around, so "j += x" is not monotonic and "j" becomes negative. | ||
| [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)] | ||
| private static int Test(int[] a, bool flag) | ||
| { | ||
| int j = 0, x = int.MaxValue - 10, sum = 0; | ||
| if (a.Length != 101) | ||
| return 0; | ||
| while (j < 101) | ||
| { | ||
| if (flag) | ||
| sum += a[j]; | ||
| x++; | ||
| if (x >= int.MinValue + 1 && x <= 10) | ||
| j += x; | ||
| } | ||
| return sum; | ||
| } | ||
| } |
This file contains hidden or 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,52 @@ | ||
| // 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_134452 | ||
| { | ||
| [Fact] | ||
| [SkipOnMono("CoreCLR JIT regression test")] | ||
| public static void TestEntryPoint() | ||
| { | ||
| Assert.Equal(1, IntToFloatRounding(16777219)); | ||
| Assert.Equal(1, DoubleToUIntSaturation(-5)); | ||
| Assert.Throws<IndexOutOfRangeException>(() => IndexThroughFloat(new byte[16777220], 16777219)); | ||
| } | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)] | ||
| private static int IntToFloatRounding(int x) | ||
| { | ||
| if (x >= 0 && x <= 16777219) | ||
| { | ||
| // (float)16777219 rounds to 16777220 | ||
| int y = (int)(float)x; | ||
| if (y > 16777219) | ||
| return 1; | ||
| } | ||
| return 0; | ||
| } | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)] | ||
| private static int DoubleToUIntSaturation(int x) | ||
| { | ||
| if (x < 0) | ||
| { | ||
| // Saturates to 0 | ||
| uint u = (uint)(double)x; | ||
| if (u == 0) | ||
| return 1; | ||
| } | ||
| return 0; | ||
| } | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)] | ||
| private static int IndexThroughFloat(byte[] arr, int x) | ||
| { | ||
| if (arr.Length == 16777220 && x >= 0 && x <= 16777219) | ||
| return arr[(int)(float)x]; | ||
| return -1; | ||
| } | ||
| } |
This file contains hidden or 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,31 @@ | ||
| // 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_134455 | ||
| { | ||
| [Fact] | ||
| public static void TestEntryPoint() | ||
| { | ||
| Assert.Throws<IndexOutOfRangeException>(() => Test(-1, 1)); | ||
| Assert.Equal(0, Test(-1, 0)); | ||
| Assert.Equal(0, Test(50, 0)); | ||
| } | ||
|
|
||
| // "x >>> (y & 3)" is a large positive value for negative "x". | ||
| [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)] | ||
| private static int Test(int x, int y) | ||
| { | ||
| int[] a = new int[51]; | ||
| if (x <= 50) | ||
| { | ||
| int v = x >>> (y & 3); | ||
| if (v >= 0) | ||
| return a[v]; | ||
| } | ||
| return 0; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.