Skip to content

JIT: (bug) fgMorphCommutative keeps GTF_ICON_CLASS_HDL on folded "H + C" constant (bogus class handle) #134475

Closed

Description

@EgorBo

After (x + H) + 8 is folded into x + (H + 8), the folded constant is still flagged as a class handle. With DOTNET_JitDisasm=Test, a Checked runtime then asserts in the VM.

Minimal Repro

using System;
using System.Runtime.CompilerServices;

public class Program
{
    [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
    static nint Test(nint x) => (x + RuntimeTypeHandle.ToIntPtr(typeof(string).TypeHandle)) + 8;

    static void Main()
    {
        nint h = RuntimeTypeHandle.ToIntPtr(typeof(string).TypeHandle);
        Console.WriteLine(Test(1) - h);
    }
}

Run with DOTNET_JitDisasm=Test on a Checked runtime.

Expected

The disasm is printed, followed by 9.

Actual

Assert failure: AsMethodTable()->SanityCheck()
CORECLR! TypeHandle::Verify
CORECLR! CEEInfo::getArrayRank
CLRJIT! Compiler::eePrintType
CLRJIT! Compiler::eeGetClassName
CLRJIT! emitter::emitDispCommentForHandle
    File: src\coreclr\vm\typehandle.cpp:39

Regression?

Release runtimes (.NET 8 through 11 RC2) don't print a handle comment here, so they aren't affected. Checked builds of older versions weren't checked.

Notes

fgMorphCommutative updates cns1 in place (value, VN and field sequence) but keeps GTF_ICON_CLASS_HDL. The emitter then passes MT+8 to the VM as a class handle. The generated code itself is correct. Possible fix: bail when either constant is IsIconHandle().

Activity

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