Skip to content

JIT: (bug) constant-folds typeof(void).IsPrimitive to true #133964

Description

@EgorBo

The importer folds Type.IsPrimitive for a known System.Void type handle to true, disagreeing with reflection, which reports false for typeof(void).IsPrimitive.

Minimal Repro

using System;
using System.Runtime.CompilerServices;

class Program
{
    [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
    static bool Folded() => typeof(void).IsPrimitive;

    [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
    static bool Runtime(Type t) => t.IsPrimitive;

    static void Main()
    {
        Console.WriteLine("folded:  " + Folded());
        Console.WriteLine("runtime: " + Runtime(typeof(void)));
    }
}

Expected

folded:  False
runtime: False

Actual

folded:  True
runtime: False

Notes

Compiler::impIntrinsic handles NI_System_Type_get_IsPrimitive by checking getTypeForPrimitiveValueClass, which returns a primitive type value for System.Void.
The fold should explicitly reject CORINFO_TYPE_VOID so it matches System.Type.IsPrimitive.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions