Skip to content

Commit 576315f

Browse files
Add a simple test that reproduces bad codegen
1 parent 7e030a8 commit 576315f

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
public class FoldingExtendsInt32On64BitHostsTest
2+
{
3+
// On 64 bit hosts, 32 bit constants are stored as 64 bit signed values.
4+
// gtFoldExpr failed to properly truncate the folded value to 32 bits when
5+
// the host was 64 bit and the target - 32 bit. Thus local assertion prop
6+
// got the "poisoned" value, which lead to silent bad codegen.
7+
8+
public static int Main()
9+
{
10+
var r1 = 31;
11+
// "Poisoned" value.
12+
var s1 = 0b11 << r1;
13+
14+
if (s1 == 0b11 << 31)
15+
{
16+
return 100;
17+
}
18+
19+
// Just so that Roslyn actually uses locals.
20+
Use(s1);
21+
Use(r1);
22+
23+
return -1;
24+
}
25+
26+
private static void Use(int a) { }
27+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>Exe</OutputType>
4+
<Optimize>True</Optimize>
5+
<DebugType>None</DebugType>
6+
</PropertyGroup>
7+
<ItemGroup>
8+
<Compile Include="$(MSBuildProjectName).cs" />
9+
</ItemGroup>
10+
</Project>

0 commit comments

Comments
 (0)