Skip to content

Commit

Permalink
Add regression test for dotnet#40607
Browse files Browse the repository at this point in the history
  • Loading branch information
echesakov committed Sep 3, 2020
1 parent 5183c6e commit 75a43a6
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
69 changes: 69 additions & 0 deletions src/tests/JIT/Regression/JitBlue/Runtime_40607/Runtime_40607.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using System;
using System.Runtime.CompilerServices;

namespace Runtime_40607
{
class Program
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static bool WillBeInlined(out bool shouldBeFalse)
{
shouldBeFalse = false;
return true;
}

[MethodImpl(MethodImplOptions.NoInlining)]
[SkipLocalsInit]
static int DependsOnUnInitValue()
{
int retVal = 1;
bool shouldBeFalse;

while (WillBeInlined(out shouldBeFalse))
{
if (shouldBeFalse)
{
retVal = 0;
}
break;
}

return retVal;
}

[MethodImpl(MethodImplOptions.NoInlining)]
static unsafe int PoisonStackWith(uint fillValue)
{
int retVal = 1;
bool shouldBeFalse;

*(uint*)&shouldBeFalse = fillValue;

while (WillBeInlined(out shouldBeFalse))
{
if (shouldBeFalse)
{
retVal = 0;
}
break;
}

return retVal;
}

static int Main(string[] args)
{
PoisonStackWith(0xdeadbeef);

const int expected = 1;
int actual = DependsOnUnInitValue();

if (expected != actual)
{
return 0;
}

return 100;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<DebugType />
<Optimize>True</Optimize>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).cs" />
</ItemGroup>
</Project>

0 comments on commit 75a43a6

Please sign in to comment.