Skip to content

JIT: (bug) NativeAOT: relational comparison of a type handle with a constant is folded using the compile-time handle placeholder #134891

Closed

Description

@EgorBo

Under NativeAOT, comparing a type handle against a numeric constant is folded using ILC's synthetic handle value (0x420000 + 8*n) instead of the real relocated address.

Minimal Repro

using System;
using System.Runtime.CompilerServices;

class Program
{
    [MethodImpl(MethodImplOptions.NoInlining)]
    static bool Test() => typeof(Program).TypeHandle.Value > 0x1000000;

    static void Main()
    {
        Console.WriteLine(typeof(Program).TypeHandle.Value.ToString("X"));
        Console.WriteLine(Test());
    }
}

Publish with PublishAot=true.

Expected

7FF686C61040
True

Actual

7FF686C61040
False

Test is compiled to xor eax, eax; ret. JIT mode prints True.

Regression?

No. Reproduces on .NET 8.0, 9.0, 10.0, 11.0-rc2 and main.

Notes

ValueNumStore::VNEvalCanFoldBinaryFunc rejects relocatable handles under compReloc for arithmetic and unsigned compares, but the GT_EQ/NE/GT/GE/LT/LE cases skip that check. gtFoldExprBinaryConstInt (via ImmedValCanBeFolded) has the same problem.

Activity

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