-
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.
Add a simple test that reproduces bad codegen
- Loading branch information
1 parent
7e030a8
commit 576315f
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
src/tests/JIT/Directed/ConstantFolding/folding_extends_int32_on_64_bit_hosts.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,27 @@ | ||
public class FoldingExtendsInt32On64BitHostsTest | ||
{ | ||
// On 64 bit hosts, 32 bit constants are stored as 64 bit signed values. | ||
// gtFoldExpr failed to properly truncate the folded value to 32 bits when | ||
// the host was 64 bit and the target - 32 bit. Thus local assertion prop | ||
// got the "poisoned" value, which lead to silent bad codegen. | ||
|
||
public static int Main() | ||
{ | ||
var r1 = 31; | ||
// "Poisoned" value. | ||
var s1 = 0b11 << r1; | ||
|
||
if (s1 == 0b11 << 31) | ||
{ | ||
return 100; | ||
} | ||
|
||
// Just so that Roslyn actually uses locals. | ||
Use(s1); | ||
Use(r1); | ||
|
||
return -1; | ||
} | ||
|
||
private static void Use(int a) { } | ||
} |
10 changes: 10 additions & 0 deletions
10
src/tests/JIT/Directed/ConstantFolding/folding_extends_int32_on_64_bit_hosts.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,10 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<Optimize>True</Optimize> | ||
<DebugType>None</DebugType> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="$(MSBuildProjectName).cs" /> | ||
</ItemGroup> | ||
</Project> |