Skip to content
Open
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
9 changes: 6 additions & 3 deletions src/coreclr/jit/gentree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34250,8 +34250,11 @@ bool Compiler::gtCanSkipCovariantStoreCheck(GenTree* value, GenTree* array)
CORINFO_CLASS_HANDLE arrayElementHandle = nullptr;
CorInfoType arrayElemType = info.compCompHnd->getChildType(arrayHandle, &arrayElementHandle);

// Verify array type handle is really an array of ref type
assert(arrayElemType == CORINFO_TYPE_CLASS);
// The array may not be an array of ref type, e.g. in a mismatched GDV-guessed inlinee.
if ((arrayElemType != CORINFO_TYPE_CLASS) || (arrayElementHandle == NO_CLASS_HANDLE))
{
return false;
}

// Check for exactly object[]
if (arrayIsExact && (arrayElementHandle == impGetObjectClass()))
Expand All @@ -34262,7 +34265,7 @@ bool Compiler::gtCanSkipCovariantStoreCheck(GenTree* value, GenTree* array)

const bool arrayTypeIsSealed = info.compCompHnd->isExactType(arrayElementHandle);

if ((!arrayIsExact && !arrayTypeIsSealed) || (arrayElementHandle == NO_CLASS_HANDLE))
if (!arrayIsExact && !arrayTypeIsSealed)
{
// Bail out if we don't know array's exact type
return false;
Expand Down
43 changes: 43 additions & 0 deletions src/tests/JIT/Regression/JitBlue/Runtime_138142/Runtime_138142.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// 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.Threading;
using Xunit;

public class Runtime_138142
{
static void Call<T>(int index, T state, Action<int, T> action) => action(index, state);

static void StoreReference()
{
object[] array = new object[1];
Call(0, array, static (i, a) => a[i] = a);
}

static void StoreNumber()
{
int[] array = new int[1];
Call(0, array, static (i, a) => a[i] = i);
}

[Fact]
public static void TestEntryPoint()
{
for (int round = 0; round < 20; round++)
{
for (int i = 0; i < 2000; i++)
StoreReference();

Thread.Sleep(20);
}

for (int round = 0; round < 100; round++)
{
for (int i = 0; i < 2000; i++)
StoreNumber();

Thread.Sleep(5);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<DebugType>None</DebugType>
<Optimize>True</Optimize>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).cs" />
</ItemGroup>
</Project>
Loading