Skip to content

Assertion failed 'fieldCorType == CORINFO_TYPE_VALUECLASS' during 'Optimize Valnum CSEs' #38541

@MichalStrehovsky

Description

@MichalStrehovsky

NGenDump leading to the assert: ngendump.txt

Compile the below with:

  • csc /noconfig /nostdlib cse.cs /r:System.Private.CoreLib.dll /O /unsafe /target:library
  • crossgen cse.dll
using System.Runtime.InteropServices;
using System;
using System.Diagnostics;

        [StructLayout(LayoutKind.Sequential)]
        struct DynamicFieldHandleInfo
        {
            public IntPtr DeclaringType;
            public IntPtr FieldName;
        }

class Foo
{
        public string GetStringFromMemoryInNativeFormat(IntPtr p) => null;

        private unsafe bool TryGetDynamicRuntimeFieldHandleComponents(RuntimeFieldHandle runtimeFieldHandle, out RuntimeTypeHandle declaringTypeHandle, out string fieldName)
        {
            IntPtr runtimeFieldHandleValue = *(IntPtr*)&runtimeFieldHandle;

            // Special flag in the handle value to indicate it was dynamically allocated
            Debug.Assert((runtimeFieldHandleValue.ToInt64() & 0x1) == 0x1);
            runtimeFieldHandleValue = runtimeFieldHandleValue - 1;

            DynamicFieldHandleInfo* fieldData = (DynamicFieldHandleInfo*)runtimeFieldHandleValue.ToPointer();
            declaringTypeHandle = *(RuntimeTypeHandle*)&(fieldData->DeclaringType);

            // FieldName points to the field name in NativeLayout format, so we parse it using a NativeParser
            IntPtr fieldNamePtr = fieldData->FieldName;
            fieldName = GetStringFromMemoryInNativeFormat(fieldNamePtr);

            return true;
        }
}

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