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
4 changes: 2 additions & 2 deletions src/coreclr/jit/importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9797,9 +9797,9 @@ void Compiler::impImportBlockCode(BasicBlock* block)
// Field's type is a byref-like struct -> address is not on the heap.
indirFlags |= GTF_IND_TGT_NOT_HEAP;
}
else
else if ((fieldInfo.fieldFlags & CORINFO_FLG_FIELD_STATIC) == 0)
{
// Field's owner is a byref-like struct -> address is not on the heap.
// Field's owner is a byref-like struct and the field is not static -> address is not on the heap.
CORINFO_CLASS_HANDLE fldOwner = info.compCompHnd->getFieldClass(resolvedToken.hField);
if ((fldOwner != NO_CLASS_HANDLE) && eeIsByrefLike(fldOwner))
{
Expand Down
48 changes: 48 additions & 0 deletions src/tests/JIT/Regression/JitBlue/Runtime_125169/Runtime_125169.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// 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 Xunit;

public readonly struct ByteArrayWrapper
{
public readonly byte[] _innerArray;

public ByteArrayWrapper(scoped in byte[] innerArray)
{
_innerArray = innerArray;
}
}

public readonly ref struct RefWrapper
{
public static readonly ByteArrayWrapper _data = new ByteArrayWrapper(new byte[] { 0, 1, 2, 3, 4 });
}

public class Runtime_125169
{
// Regression test for bug in JIT where ref struct static fields of reference type initialized in
// its static constructor were missing calls to JIT_ByRefWriteBarrier for each such static field.
[Fact]
public static void TestEntryPoint()
{
byte[][] arr = new byte[100][];
// Generate enough garbage
for (int i = 0; i < 100; i++)
{
arr[i] = new byte[100000];
}

ReadOnlySpan<byte> testSpan = new(RefWrapper._data._innerArray);
// Without the fix, the following GC.Collect call causes fatal error during heap verification with DOTNET_HeapVerify=1
GC.Collect(0);

// Prevent the compiler from optimizing out the loop above.
GC.KeepAlive(arr);

for (int i = 0; i < testSpan.Length; i++)
{
Assert.Equal(i, testSpan[i]);
}
}
}
1 change: 1 addition & 0 deletions src/tests/JIT/Regression/Regression_ro_2.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
<Compile Include="JitBlue\Runtime_124507\Runtime_124507.cs" />
<Compile Include="JitBlue\Runtime_125041\Runtime_125041.cs" />
<Compile Include="JitBlue\Runtime_125058\Runtime_125058.cs" />
<Compile Include="JitBlue\Runtime_125169\Runtime_125169.cs" />
<Compile Include="JitBlue\Runtime_125301\Runtime_125301.cs" />
<Compile Include="JitBlue\Runtime_125328\Runtime_125328.cs" />
</ItemGroup>
Expand Down
Loading