Skip to content

Commit 704128b

Browse files
AndyAyersMSgithub-actions
authored andcommitted
review feedback
1 parent d2c0771 commit 704128b

2 files changed

Lines changed: 41 additions & 6 deletions

File tree

src/coreclr/vm/jitinterface.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8613,18 +8613,18 @@ bool CEEInfo::resolveVirtualMethodHelper(CORINFO_DEVIRTUALIZATION_INFO * info)
86138613

86148614
if (pObjMT->IsArray())
86158615
{
8616+
if (pBaseMT->IsSharedByGenericInstantiations())
8617+
{
8618+
info->detail = CORINFO_DEVIRTUALIZATION_FAILED_CANON;
8619+
return false;
8620+
}
8621+
86168622
// Does the array implicitly implement this interface?
86178623
//
86188624
isArrayImplicitInterface = pBaseMT->HasInstantiation() && IsImplicitInterfaceOfSZArray(pBaseMT);
86198625

86208626
if (!isArrayImplicitInterface)
86218627
{
8622-
if (pBaseMT->IsSharedByGenericInstantiations())
8623-
{
8624-
info->detail = CORINFO_DEVIRTUALIZATION_FAILED_CANON;
8625-
return false;
8626-
}
8627-
86288628
// Ensure we can cast the array to the interface type
86298629
//
86308630
if (!TypeHandle(pObjMT).CanCastTo(TypeHandle(pBaseMT)))
@@ -8653,6 +8653,7 @@ bool CEEInfo::resolveVirtualMethodHelper(CORINFO_DEVIRTUALIZATION_INFO * info)
86538653
// The instantiation we want is based on the interface element type, not the
86548654
// array element type.
86558655
TypeHandle resultElemType = pBaseMT->GetInstantiation()[0];
8656+
// We should have ruled this out above.
86568657
_ASSERTE(!resultElemType.IsCanonicalSubtype());
86578658
pDevirtMD = GetActualImplementationForArrayGenericIListOrIReadOnlyListMethod(pBaseMD, resultElemType);
86588659
}

src/tests/JIT/Regression/JitBlue/Runtime_120270/Runtime_120270.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33

44
using System;
55
using System.Linq;
6+
using System.Runtime.CompilerServices;
67
using Xunit;
78

9+
class Base{}
10+
class Derived : Base {}
11+
812
public class Runtime_120270
913
{
1014
[Fact]
@@ -32,5 +36,35 @@ public static int TestEntryPoint()
3236

3337
return failed ? -1 : 100;
3438
}
39+
40+
[Fact]
41+
public static int TestEntryPoint2()
42+
{
43+
bool failed = false;
44+
try
45+
{
46+
Foo<Base>([new Derived()]);
47+
}
48+
catch (Exception ex)
49+
{
50+
Console.WriteLine(ex);
51+
failed = true;
52+
}
53+
return failed ? -1 : 100;
54+
}
55+
56+
[MethodImpl(MethodImplOptions.NoInlining)]
57+
static void Foo<T>(object[] x)
58+
{
59+
int i = 0;
60+
while (i < 100_000)
61+
{
62+
i++;
63+
var values = x.Cast<T>();
64+
foreach (var value in values)
65+
{
66+
}
67+
}
68+
}
3569
}
3670

0 commit comments

Comments
 (0)