Skip to content

Commit 451a41d

Browse files
authored
Don't emit unchecked write barrier for stack-allocated arrays (#112711)
1 parent b71cad1 commit 451a41d

File tree

3 files changed

+51
-2
lines changed

3 files changed

+51
-2
lines changed

src/coreclr/jit/assertionprop.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -5193,8 +5193,9 @@ static GCInfo::WriteBarrierForm GetWriteBarrierForm(Compiler* comp, ValueNum vn)
51935193
{
51945194
if (funcApp.m_func == VNF_PtrToArrElem)
51955195
{
5196-
// Arrays are always on the heap
5197-
return GCInfo::WriteBarrierForm::WBF_BarrierUnchecked;
5196+
// Check whether the array is on the heap
5197+
ValueNum arrayVN = funcApp.m_args[1];
5198+
return GetWriteBarrierForm(comp, arrayVN);
51985199
}
51995200
if (funcApp.m_func == VNF_PtrToLoc)
52005201
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
// Generated by Fuzzlyn v2.4 on 2025-02-19 20:47:50
5+
// Run on X64 Windows
6+
// Seed: 12432040051036532696-vectort,vector128,vector256,x86aes,x86avx,x86avx2,x86avx512bw,x86avx512bwvl,x86avx512cd,x86avx512cdvl,x86avx512dq,x86avx512dqvl,x86avx512f,x86avx512fvl,x86avx512fx64,x86bmi1,x86bmi1x64,x86bmi2,x86bmi2x64,x86fma,x86lzcnt,x86lzcntx64,x86pclmulqdq,x86popcnt,x86popcntx64,x86sse,x86ssex64,x86sse2,x86sse2x64,x86sse3,x86sse41,x86sse41x64,x86sse42,x86sse42x64,x86ssse3,x86x86base
7+
// Reduced from 62.0 KiB to 0.5 KiB in 00:06:15
8+
// Exits with error:
9+
// Fatal error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
10+
// at Program.Main(Fuzzlyn.ExecutionServer.IRuntime)
11+
// at Fuzzlyn.ExecutionServer.Program.<RunPairAsync>g__RunAndGetResultAsync|1_0(Byte[], <>c__DisplayClass1_0 ByRef)
12+
// at Fuzzlyn.ExecutionServer.Program.RunPairAsync(System.Runtime.Loader.AssemblyLoadContext, Fuzzlyn.ExecutionServer.ProgramPair)
13+
// at Fuzzlyn.ExecutionServer.Program+<>c__DisplayClass0_0.<Main>b__0()
14+
// at System.Threading.Thread+StartHelper.RunWorker()
15+
//
16+
using System;
17+
using System.Numerics;
18+
using System.Runtime.Intrinsics;
19+
using System.Runtime.Intrinsics.X86;
20+
using Xunit;
21+
22+
public class Runtime_112709
23+
{
24+
[Fact]
25+
public static void Problem()
26+
{
27+
Vector256<byte>[][][] vr0 = default(Vector256<byte>[][][]);
28+
vr0 = new Vector256<byte>[][][]
29+
{
30+
new Vector256<byte>[][]
31+
{
32+
new Vector256<byte>[]
33+
{
34+
Vector256.Create<byte>(0)
35+
}
36+
}
37+
};
38+
vr0[0] = vr0[0];
39+
}
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<Optimize>True</Optimize>
4+
</PropertyGroup>
5+
<ItemGroup>
6+
<Compile Include="$(MSBuildProjectName).cs" />
7+
</ItemGroup>
8+
</Project>

0 commit comments

Comments
 (0)