Skip to content

JIT: (bug) Copying a struct larger than 64 KiB silently drops fields past the 64 KiB mark #133581

Closed

Description

@EgorBo

Repro

using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Explicit, Size = 65600)]
struct Big
{
    [FieldOffset(0)]     public int Head;
    [FieldOffset(65592)] public object O;   // one GC slot, past 64 KiB
}

class Holder
{
    public Big B;
}

class Program
{
    [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
    static void Test(Holder h)
    {
        Big b = default;
        b.Head = 42;
        b.O = "payload";
        h.B = b;
    }

    static void Main()
    {
        var h = new Holder();
        Test(h);
        Console.WriteLine($"{h.B.Head}, {h.B.O ?? "<null>"}");
    }
}

Expected

42, payload

Actual

42, <null>

A Checked build also asserts while jitting Test:

Assertion failed 'lclOffs <= UINT16_MAX' in 'Program:Test(Holder)' during 'Lowering nodeinfo'

The struct copy loses anything stored beyond offset 65535, so the reference field arrives as null;
a ref Big destination loses it the same way. Structs this large are legal C#.

Platform

Windows x64, .NET 11 (dotnet/runtime main @ a0b86b1). Reproduces on Checked and Release builds
with DOTNET_TieredCompilation=0.

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. EgorBo commented on Sep 18, 2026

    @EgorBo
    MemberAuthor

    Affected SDK versions:

    • 11.0.100-rc.2.26467.112
  5. self-assigned this
    on Oct 9, 2026
  6. locked and limited conversation to collaborators on Nov 10, 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