Skip to content

JIT: (bug) Forward substitution drops a promoted struct's defining store #133641

Description

@EgorBo
using System;
using System.Runtime.CompilerServices;

class Program
{
    struct S { public long A; public long B; public long C; }

    [MethodImpl(MethodImplOptions.NoInlining)]
    static long Combine(S s, long a, long b) => s.A + s.B + s.C + a + b;

    [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
    static long Test(S input)
    {
        S s = input;
        input.A = 42;
        long p = s.A;
        return Combine(s, p, p);
    }

    static void Main() => Console.WriteLine(Test(new S { A = 1, B = 2, C = 3 }));
}

Expected output: 8
Actual output: 6

windows-x64, main @ a0b86b1.

Goes away with DOTNET_JitNoForwardSub=1.

Activity

  1. added this to the 12.0.0 milestone on Sep 10, 2026
  2. added
    area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
    on Sep 10, 2026
  3. dotnet-policy-service commented on Sep 10, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
    See info in area-owners.md if you want to be subscribed.

  4. self-assigned this
    on Sep 10, 2026
  5. AndyAyersMS commented on Sep 10, 2026

    @AndyAyersMS
    Member

    Taking a look...

  6. AndyAyersMS commented on Sep 10, 2026

    @AndyAyersMS
    Member

    Seems like this came from my #129312 so is new in .NET 11.

  7. added a commit that references this issue on Sep 18, 2026
    539d1a2
  8. EgorBo commented on Sep 18, 2026

    @EgorBo
    MemberAuthor

    Affected SDK versions:

    • 11.0.100-rc.2.26467.112
  9. EgorBo commented on Sep 18, 2026

    @EgorBo
    MemberAuthor

    @AndyAyersMS would you consider backporting the fix from #133703 to release/11.0?

    It currently only exists in main (12.0). The repro still fails on the shipped 11.0 RC2 SDK (11.0.100-rc.2.26467.112), while 8.0.425, 9.0.318 and 10.0.401 all behave correctly, so this is a regression introduced during the 11.0 cycle rather than a long-standing bug — 11.0 would ship with it.

    Note: this comment was produced by an AI agent; the repro was re-run against all four released SDKs to confirm the results above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions