diff --git a/src/coreclr/jit/objectalloc.cpp b/src/coreclr/jit/objectalloc.cpp index 78ca1537d26a56..604049cb34a81d 100644 --- a/src/coreclr/jit/objectalloc.cpp +++ b/src/coreclr/jit/objectalloc.cpp @@ -1906,6 +1906,19 @@ void ObjectAllocator::AnalyzeParentStack(ArrayStack* parentStack, unsi break; } + // For structs we need to check the layout as well + // + if (parent->OperIs(GT_BLK)) + { + ClassLayout* const layout = parent->AsBlk()->GetLayout(); + + if (!layout->HasGCPtr()) + { + canLclVarEscapeViaParentStack = false; + break; + } + } + GenTree* const addr = parent->AsIndir()->Addr(); // For loads from local structs we may be tracking the underlying fields. diff --git a/src/tests/JIT/opt/ObjectStackAllocation/Runtime_115831.cs b/src/tests/JIT/opt/ObjectStackAllocation/Runtime_115831.cs new file mode 100644 index 00000000000000..cf1d758f1e4201 --- /dev/null +++ b/src/tests/JIT/opt/ObjectStackAllocation/Runtime_115831.cs @@ -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. + +// Generated by Fuzzlyn v3.0 on 2025-05-20 21:40:51 +// Run on X64 Windows +// 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 +// Reduced from 52.0 KiB to 0.5 KiB in 00:03:45 +// Hits JIT assert in Release: +// Assertion failed 'newType == TYP_I_IMPL' in 'Program:Main(Fuzzlyn.ExecutionServer.IRuntime)' during 'Allocate Objects' (IL size 47; hash 0xade6b36b; FullOpts) +// +// File: D:\a\_work\1\s\src\coreclr\jit\objectalloc.cpp Line: 2427 +// +using System; +using System.Numerics; +using Xunit; + +public class C1 +{ +} + +public struct S2 +{ + public Vector F0; +} + +public struct S3 +{ + public S2 F3; + public C1 F5; +} + +public class Runtime_115831 +{ + public static S3 s_1; + [Fact] + public static void Problem() + { + S3 vr0 = s_1; + S2 vr1 = vr0.F3; + vr0.F5 = new C1(); + System.Console.WriteLine(vr1.F0); + } +} \ No newline at end of file diff --git a/src/tests/JIT/opt/ObjectStackAllocation/Runtime_115831.csproj b/src/tests/JIT/opt/ObjectStackAllocation/Runtime_115831.csproj new file mode 100644 index 00000000000000..501217e4d86892 --- /dev/null +++ b/src/tests/JIT/opt/ObjectStackAllocation/Runtime_115831.csproj @@ -0,0 +1,9 @@ + + + None + True + + + + +