Skip to content

Commit

Permalink
Repro case for dotnet#87597
Browse files Browse the repository at this point in the history
  • Loading branch information
davidwrighton committed Jul 12, 2023
1 parent 11fbd15 commit 7adc06c
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/tests/Regressions/coreclr/GitHub_87597/GitHub_87597.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Runtime.CompilerServices;

// Class init for devirtualized calls triggered by PGO does not behave correctly
// This test requires a class initializer on both the interface and on the type in use
// and requires that type to be generic

public class GitHub_87597
{
public interface IFace
{
static IFace() {}
void Method();
}

public class GenericType<T> : IFace
{
static GenericType()
{
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Method()
{
}
}

[MethodImpl(MethodImplOptions.NoInlining)]
public static void TestL1(IFace iface)
{
iface.Method();
}

public static int Main()
{
for (int i = 0; i < 100; i++)
{
System.Threading.Thread.Sleep(16);
TestL1(new GenericType<string>());
}

return 100;
}
}
10 changes: 10 additions & 0 deletions src/tests/Regressions/coreclr/GitHub_87597/GitHub_87597.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Optimize>True</Optimize>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildThisFileName).cs" />
</ItemGroup>
</Project>

0 comments on commit 7adc06c

Please sign in to comment.