Skip to content

Commit ed055b1

Browse files
authored
JIT: also check gc-ness of layout for GT_BLK during escape analysis (#115844)
Otherwise we may mistakenly build a connection to the unknown source and try retyping a non-gc struct. Fixes #115831.
1 parent 3d23851 commit ed055b1

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

src/coreclr/jit/objectalloc.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1906,6 +1906,19 @@ void ObjectAllocator::AnalyzeParentStack(ArrayStack<GenTree*>* parentStack, unsi
19061906
break;
19071907
}
19081908

1909+
// For structs we need to check the layout as well
1910+
//
1911+
if (parent->OperIs(GT_BLK))
1912+
{
1913+
ClassLayout* const layout = parent->AsBlk()->GetLayout();
1914+
1915+
if (!layout->HasGCPtr())
1916+
{
1917+
canLclVarEscapeViaParentStack = false;
1918+
break;
1919+
}
1920+
}
1921+
19091922
GenTree* const addr = parent->AsIndir()->Addr();
19101923

19111924
// For loads from local structs we may be tracking the underlying fields.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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 v3.0 on 2025-05-20 21:40:51
5+
// Run on X64 Windows
6+
// Seed: 11262416476118799467-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 52.0 KiB to 0.5 KiB in 00:03:45
8+
// Hits JIT assert in Release:
9+
// Assertion failed 'newType == TYP_I_IMPL' in 'Program:Main(Fuzzlyn.ExecutionServer.IRuntime)' during 'Allocate Objects' (IL size 47; hash 0xade6b36b; FullOpts)
10+
//
11+
// File: D:\a\_work\1\s\src\coreclr\jit\objectalloc.cpp Line: 2427
12+
//
13+
using System;
14+
using System.Numerics;
15+
using Xunit;
16+
17+
public class C1
18+
{
19+
}
20+
21+
public struct S2
22+
{
23+
public Vector<ushort> F0;
24+
}
25+
26+
public struct S3
27+
{
28+
public S2 F3;
29+
public C1 F5;
30+
}
31+
32+
public class Runtime_115831
33+
{
34+
public static S3 s_1;
35+
[Fact]
36+
public static void Problem()
37+
{
38+
S3 vr0 = s_1;
39+
S2 vr1 = vr0.F3;
40+
vr0.F5 = new C1();
41+
System.Console.WriteLine(vr1.F0);
42+
}
43+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<DebugType>None</DebugType>
4+
<Optimize>True</Optimize>
5+
</PropertyGroup>
6+
<ItemGroup>
7+
<Compile Include="$(MSBuildProjectName).cs" />
8+
</ItemGroup>
9+
</Project>

0 commit comments

Comments
 (0)