diff --git a/src/coreclr/jit/sideeffects.cpp b/src/coreclr/jit/sideeffects.cpp index 5f90c8d90456c7..a3f63b07e362ba 100644 --- a/src/coreclr/jit/sideeffects.cpp +++ b/src/coreclr/jit/sideeffects.cpp @@ -318,6 +318,19 @@ void AliasSet::AddNode(Compiler* compiler, GenTree* node) if (nodeInfo.IsLclVarWrite()) { m_lclVarWrites.Add(compiler, nodeInfo.LclNum()); + + LclVarDsc* dsc = compiler->lvaGetDesc(nodeInfo.LclNum()); + if (dsc->lvIsStructField) + { + m_lclVarWrites.Add(compiler, dsc->lvParentLcl); + } + else if (dsc->lvPromoted) + { + for (unsigned i = 0; i < dsc->lvFieldCnt; i++) + { + m_lclVarWrites.Add(compiler, dsc->lvFieldLclStart + i); + } + } } } diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_126414/Runtime_126414.cs b/src/tests/JIT/Regression/JitBlue/Runtime_126414/Runtime_126414.cs new file mode 100644 index 00000000000000..f71b0d6e5f7ba4 --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_126414/Runtime_126414.cs @@ -0,0 +1,60 @@ +// 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.Runtime.CompilerServices; +using Xunit; + +namespace Runtime_126414; + +public readonly struct Endpoint +{ + public Endpoint(Endpoint e) + { + A = e.A; + B = e.B; + C = e.C; + } + + public Endpoint(int a, int b, int c) { A = a; B = b; C = c; } + + public int A { get; } + public int B { get; } + public int C { get; } +} + +public sealed class Range +{ + private readonly Endpoint m_start; + private readonly Endpoint m_end; + + // Using AggressiveOptimization to force reproduction of the bug which would eventually occur when tiered compilation optimizes the constructor + [MethodImpl(MethodImplOptions.AggressiveOptimization)] + public Range(Endpoint start, Endpoint end) + { + m_start = new Endpoint(start); // Copy via copy constructor + m_end = new Endpoint(end); // Copy via copy constructor + } + + public int Length => m_end.A - m_start.A; +} + +public class Program +{ + [Fact] + public static int TestEntryPoint() + { + const int expected = 5759; + + var r = new Range(new Endpoint(100, 0, 0), new Endpoint(100 + expected, 0, 0)); + + if (r.Length != expected) + { + Console.WriteLine($"FAIL: Length={r.Length} (expected {expected}), hex=0x{r.Length:X}"); + return 101; + } + + Console.WriteLine($"PASS: Length = {expected}"); + return 100; + } +} diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_126414/Runtime_126414.csproj b/src/tests/JIT/Regression/JitBlue/Runtime_126414/Runtime_126414.csproj new file mode 100644 index 00000000000000..501217e4d86892 --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_126414/Runtime_126414.csproj @@ -0,0 +1,9 @@ + + + None + True + + + + +