Skip to content

JIT: (bug) [ARM64] genPutArgStk gives both LDP destination registers the first field's GC type (bogus/missing GC roots) #134066

Closed

Description

@EgorBo

In CodeGen::genPutArgStk (codegenarmarch.cpp), the 16-byte ldp from an address expression passes
emitTypeSize(type0) as the second register's GC attribute (attrReg2):

emit->emitIns_R_R_R_I(INS_ldp, emitTypeSize(type0), loReg, hiReg, addrReg, structOffset,
                      INS_OPTS_NONE, emitTypeSize(type0));   // <- should be emitTypeSize(type1)

The adjacent local-source ldp and the following stp both correctly use emitTypeSize(type1).
As a result, in a fully interruptible method, the second register is described with the first field's
GC-ness: a non-GC half is reported as a live GC reference (bogus root), or a reference half goes
unreported (missing root).

Repro

using System;
using System.Runtime.CompilerServices;

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

public class Program
{
    static int s_x;

    [MethodImpl(MethodImplOptions.NoInlining)]
    static void Consume(long a, long b, long c, long d, long e, long f, long g, long h, S s)
    {
        if (s.A != 42 || (string)s.B != "hello") throw new Exception("bad");
    }

    [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
    static void Test(C c)
    {
        while (s_x != 0) { s_x--; } // call-free loop => method is fully interruptible
        Consume(1, 2, 3, 4, 5, 6, 7, 8, c.S);
    }

    public static int Main()
    {
        C c = new C();
        c.S.A = 42;
        c.S.B = "hello";
        for (int i = 0; i < 1000; i++) Test(c);
        Console.WriteLine("done");
        return 100;
    }
}

Run on linux-arm64: DOTNET_TieredCompilation=0 DOTNET_GCStress=0x4 corerun repro.dll

Expected

done

Actual

crash

Notes

  • DOTNET_JitDisasm=Test DOTNET_JitDisasmWithGC=1 shows the defect directly: ldp x1, x2, [x0] followed by
    ; gcrRegs +[x1-x2] — x2 holds S.A (the long, value 42) but is reported live-GC until mov x2, #3.
  • Controls under identical settings all pass, isolating the attrReg2 argument:
    struct S { object B1; object B2; } (both halves GC), passing the struct from a local instead of c.S
    (takes the correct emitIns_R_R_S_S path), and setting A = 0 (bogus root looks null).
  • DOTNET_JitFullyInt=1 without the loop reproduces identically.
  • Fix: pass emitTypeSize(type1) as the final argument.

Activity

  1. added
    area-CodeGen-coreclr
    on Sep 16, 2026
  2. added
    untriaged
    on Sep 16, 2026
  3. dotnet-policy-service commented on Sep 16, 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. removed
    untriaged
    on Sep 16, 2026
  5. added this to the 12.0.0 milestone on Sep 16, 2026
  6. self-assigned this
    on Oct 12, 2026
  7. added a commit that references this issue on Oct 14, 2026
    55d6c84
  8. locked and limited conversation to collaborators on Nov 13, 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-coreclr

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions