-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Surgical fix for bad assertion generation (#55626)
* Add a test * Surgical fix for bad assertion generation Say we have a cast like this: CAST(uint <- long). What value does this tree compute? [int.MinValue..int.MaxValue] - IR operates on signed TYP_INTs. But assertion prop generated [0..uint.MaxValue] for it. The confusion created by this "how to interpret TYP_UINT" question caused a bug where for the assertion generated for the above cast, in the form of [0..uint.MaxValue], propagation could remove a checked cast in the form of CAST_OVF(uint < int). The proper fix is to generate proper ranges for such casts. The surgical fix proposed here is to always treat casts to TYP_UINT as if they were to TYP_INT. This is conservative, but always correct. The generated assertion is useless of course, but that makes this a zero-diff change. * Add a comment explaining the quirk
- Loading branch information
1 parent
39135a4
commit 5bcf2c6
Showing
3 changed files
with
57 additions
and
0 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
32 changes: 32 additions & 0 deletions
32
src/tests/JIT/Regression/JitBlue/Runtime_54842/Runtime_54842.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,32 @@ | ||
using System; | ||
using System.Runtime.CompilerServices; | ||
|
||
public class Runtime_54842 | ||
{ | ||
public static int Main() | ||
{ | ||
try | ||
{ | ||
DoubleCheckedConvert(uint.MaxValue); | ||
} | ||
catch (OverflowException) | ||
{ | ||
return 100; | ||
} | ||
|
||
return 101; | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
private static uint DoubleCheckedConvert(ulong a) | ||
{ | ||
var b = (int)checked((uint)a); | ||
|
||
// Make sure the importer spills "b" to a local. | ||
Use(b); | ||
|
||
return checked((uint)b); | ||
} | ||
|
||
private static void Use(int value) { } | ||
} |
12 changes: 12 additions & 0 deletions
12
src/tests/JIT/Regression/JitBlue/Runtime_54842/Runtime_54842.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,12 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<DebugType>None</DebugType> | ||
<Optimize>True</Optimize> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="$(MSBuildProjectName).cs" /> | ||
</ItemGroup> | ||
</Project> |