Skip to content

JIT: (bug) Assert (constIndexOffset % elemSize) == 0 in GenTreeArrAddr::ParseArrayAddress for 3-byte element arrays #134192

Description

@EgorBo

ParseArrayAddressWork folds the constant index component with wrapping native arithmetic and then asserts the accumulated offset is divisible by the element size, which only holds for element sizes dividing 2^64.

Minimal Repro

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

[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct S3 { public byte A, B, C; }

public class Program
{
    [MethodImpl(MethodImplOptions.NoInlining)]
    public static byte Get(S3[] a, long x) => a[x + 6148914691236517206L].A;

    public static void Main()
    {
        var a = new S3[4];
        a[0].A = 42;
        Console.WriteLine(Get(a, -6148914691236517206L)); // index 0
    }
}

Expected

42

Actual

Assert failure: Assertion failed '(constIndexOffset % elemSize) == 0' in 'Program:Get(S3[],long):byte'
during 'Do value numbering' (IL size 24; hash 0x6f6c0c6c; FullOpts)
File: src\coreclr\jit\gentree.cpp:22035

Notes

Checked x64. The index expression sums to exactly 0 at the language level — no overflow occurs in the source; the wrap (0x5555555555555556 * 3 → 2) happens only inside the JIT's own address re-association.
Released .NET 10.0.12 prints 42, i.e. the assert is Checked-only. Whether the Release JIT silently truncates the remainder when forming the element VN was not verified and needs separate triage.

Activity

  1. added this to the 12.0.0 milestone on Sep 18, 2026
  2. added
    area-CodeGen-coreclr
    on Sep 18, 2026
  3. dotnet-policy-service commented on Sep 18, 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 21, 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