提交 caa0f882 编写于 作者: A Andrew Au 提交者: GitHub

[crossgen2] Avoid ambiguous devirtualization (dotnet/coreclr#27424)



Commit migrated from https://github.com/dotnet/coreclr/commit/d374f8c99e7092470366a88ea2abc1001d05864f
上级 dfebf8d3
......@@ -30,6 +30,34 @@ protected override MethodDesc ResolveVirtualMethod(MethodDesc declMethod, DefTyp
if (_compilationModuleGroup.VersionsWithMethodBody(declMethod) &&
_compilationModuleGroup.VersionsWithType(implType))
{
/**
* It is possible for us to hit a scenario where a type implements
* the same interface more than once due to generic instantiations.
*
* In some instances of those cases, the VirtualMethodAlgorithm
* does not produce identical output as CoreCLR would, leading to
* behavioral differences in compiled outputs.
*
* Instead of fixing the algorithm (in which the work to fix it is
* tracked in https://github.com/dotnet/corert/issues/208), the
* following duplication detection algorithm will detect the case and
* refuse to devirtualize for those scenarios.
*/
if (declMethod.OwningType.IsInterface)
{
DefType[] implTypeRuntimeInterfaces = implType.RuntimeInterfaces;
for (int i = 0; i < implTypeRuntimeInterfaces.Length; i++)
{
for (int j = i + 1; j < implTypeRuntimeInterfaces.Length; j++)
{
if (implTypeRuntimeInterfaces[i] == implTypeRuntimeInterfaces[j])
{
return null;
}
}
}
}
return base.ResolveVirtualMethod(declMethod, implType);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册