Skip to content

JIT: (bug) Native-int-typed stack address is CSE'd across an await and reused after resumption #133588

Closed

Description

@EgorBo

Repro

using System;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;

public static class Program
{
    struct Buf { public int E0, E1, E2, E3, E4, E5, E6, E7; }

    [MethodImpl(MethodImplOptions.NoInlining)]
    static void Sink(ref int x) { x += 1; }

    [MethodImpl(MethodImplOptions.NoInlining)]
    static async Task<int> Test(int index)
    {
        Buf buf = default;
        Sink(ref Unsafe.Add(ref Unsafe.As<Buf, int>(ref buf), index));
        await Task.Yield();
        Sink(ref Unsafe.Add(ref Unsafe.As<Buf, int>(ref buf), index));
        return buf.E0 + buf.E1 + buf.E2 + buf.E3 + buf.E4 + buf.E5 + buf.E6 + buf.E7;
    }

    public static int Main()
    {
        Console.WriteLine("start");
        int r = Test(1).GetAwaiter().GetResult();
        Console.WriteLine("result = " + r);
        return 100;
    }
}

Requires <Features>runtime-async=on</Features> in the project file.

Expected

start
result = 2

Actual

start
result = 1

The second Sink call writes through the address computed before the suspension, so the increment
lands in the abandoned frame instead of buf.E1. The Unsafe.As<Buf, int> is what makes the
address native-int-typed rather than byref: writing Unsafe.Add(ref buf.E0, index) instead keeps it
byref-typed and prints the correct result = 2. Setting DOTNET_JitNoCSE=1 also restores
result = 2.

Platform

Windows x64, .NET 11 (dotnet/runtime main @ a0b86b1), DOTNET_TieredCompilation=0, runtime async
enabled. No special CPU features. Output above is from the Release build and is stable across runs;
on the Checked build the same program instead dies with an access violation after printing start
(exit code -1073741819).

Activity

  1. added this to the 12.0.0 milestone on Sep 10, 2026
  2. added
    area-CodeGen-coreclr
    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. EgorBo commented on Sep 18, 2026

    @EgorBo
    MemberAuthor

    Affected SDK versions:

    • 10.0.401
    • 11.0.100-rc.2.26467.112
  6. added 2 commits that reference this issue on Sep 23, 2026
    cb62449
    990f0b0
  7. locked and limited conversation to collaborators on Oct 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclrruntime-async

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions