Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1179,14 +1179,19 @@ private bool resolveVirtualMethod(CORINFO_DEVIRTUALIZATION_INFO* info)
return false;
}

TypeDesc owningType = impl.OwningType;

// RyuJIT expects to get the canonical form back
impl = impl.GetCanonMethodTarget(CanonicalFormKind.Specific);

if (impl.OwningType.IsValueType)
{
impl = getUnboxingThunk(impl);
}

info->devirtualizedMethod = ObjectToHandle(impl);
info->requiresInstMethodTableArg = false;
info->exactContext = contextFromType(impl.OwningType);
info->exactContext = contextFromType(owningType);

return true;
}
Expand Down
30 changes: 30 additions & 0 deletions src/tests/JIT/opt/Devirtualization/generic_noinline.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// 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 Program
{
static int Main()
{
MyStruct<Atom> s = default;

// RyuJIT can devirtualize this, but NoInlining prevents the inline
// This checks that we properly pass the instantiation context to the shared generic method.
return ((IFoo)s).GetTheType() == typeof(Atom) ? 100 : -1;
}
}

interface IFoo
{
Type GetTheType();
}

struct MyStruct<T> : IFoo
{
[MethodImpl(MethodImplOptions.NoInlining)]
Type IFoo.GetTheType() => typeof(T);
}

class Atom { }
13 changes: 13 additions & 0 deletions src/tests/JIT/opt/Devirtualization/generic_noinline.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<CLRTestPriority>0</CLRTestPriority>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to make this Pri 1, but I want this to run in the CI first.

</PropertyGroup>
<PropertyGroup>
<DebugType>PdbOnly</DebugType>
<Optimize>True</Optimize>
</PropertyGroup>
<ItemGroup>
<Compile Include="generic_noinline.cs" />
</ItemGroup>
</Project>