Skip to content

Commit

Permalink
Add a test
Browse files Browse the repository at this point in the history
  • Loading branch information
EgorBo committed Apr 8, 2021
1 parent 295bcdc commit aec96ad
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/tests/JIT/opt/Devirtualization/GitHub_50492.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System.Runtime.CompilerServices;
using System.Threading;

class Base
{
public virtual int Test(Base b1, Base b2, bool p) => 0;

public virtual int Foo() => 1;
}

class ClassA : Base
{
public override int Test(Base b1, Base b2, bool p) => p ? b2.Foo() : 42;
}

class ClassB : ClassA
{
public override int Test(Base b1, Base b2, bool p) => b1.Test(b1, b2, p);
}

class Program
{
public static int Main()
{
for (int i = 0; i < 100; i++)
{
// Make sure it doesn't assert, see https://github.com/dotnet/runtime/issues/50492
Test(new ClassB(), new ClassA(), new Base(), true);
Thread.Sleep(15);
}
return 100;
}

[MethodImpl(MethodImplOptions.NoInlining)]
static int Test(Base b0, Base b1, Base b2, bool p)
{
return b0.Test(b1, b2, p);
}
}
9 changes: 9 additions & 0 deletions src/tests/JIT/opt/Devirtualization/GitHub_50492.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<Optimize>True</Optimize>
</PropertyGroup>
<ItemGroup>
<Compile Include="GitHub_50492.cs" />
</ItemGroup>
</Project>

0 comments on commit aec96ad

Please sign in to comment.