Skip to content

JIT: (bug) Assert varTypeIsIntegral(type) || varTypeIsGC(type) in morph: comma-throw propagated into a struct-typed parent #133862

Closed

Description

@EgorBo

fgPropagateCommaThrow calls BashToZeroConst(genActualType(parent)) for any non-void parent. With a
struct-typed parent (here a GT_BLK from a struct array load) this asserts in a Checked JIT and builds
malformed struct-typed CNS_INT IR in Release.

Minimal Repro

using System;
using System.Runtime.CompilerServices;

struct S { public int a, b, c, d; }

class Program
{
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    static int Idx(long v) => checked((int)v);

    [MethodImpl(MethodImplOptions.NoInlining)]
    static S Test(S[] a) => a[Idx(long.MaxValue)];

    static void Main()
    {
        try { Console.WriteLine(Test(new S[4]).a); }
        catch (OverflowException) { Console.WriteLine("OverflowException"); }
    }
}

Requires DOTNET_TieredCompilation=0; at tier-0 the folding does not happen.

Expected

OverflowException

Actual

Assert failure(PID 148588 [0x0002446c], Thread: 59900 [0xe9fc]): Assertion failed
'varTypeIsIntegral(type) || varTypeIsGC(type)' in 'Program:Test(S[]):S' during 'Morph - Global'
(IL size 21; hash 0xb183d2e0; FullOpts)

    File: src\coreclr\jit\compiler.hpp:2191

Process exits with 0xC0000409.

Notes

After inlining, gtFoldExprConst turns the always-throwing checked cast into COMMA(throw, 0), which
fgPropagateCommaThrow then propagates into the struct-typed parent; it should bail out (or use a different
"zero" representation) when the parent is not integral/GC-typed.
Span<S> indexing and S s = a[Idx(long.MaxValue)]; hit the same assert.
Release .NET 10.0.12 prints OverflowException — this is a Checked-assert / malformed-IR issue, not a known
silent bad-codegen bug.

Activity

  1. added this to the 12.0.0 milestone on Sep 14, 2026
  2. added
    area-CodeGen-coreclr
    on Sep 14, 2026
  3. dotnet-policy-service commented on Sep 14, 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
  5. added a commit that references this issue on Sep 25, 2026
    6105ed4
  6. 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-coreclr

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions