Fix RuntimeTypeHandle underlying type for CoreRT (dotnet/coreclr#14026)
authorJan Kotas <jkotas@microsoft.com>
Mon, 18 Sep 2017 18:01:41 +0000 (11:01 -0700)
committerGitHub <noreply@github.com>
Mon, 18 Sep 2017 18:01:41 +0000 (11:01 -0700)
RuntimeTypeHandles on CoreRT are backed by IntPtr today. This fix is not complete. There are likely more places that make assumption about the underlying runtime handle types, but this is enough to fix the immediate problem hit by @sergign60.

Commit migrated from https://github.com/dotnet/coreclr/commit/4aca96e9f2572e66a687d1f4d418e9545c6cb4cb

src/coreclr/src/jit/compiler.h
src/coreclr/src/jit/importer.cpp

index 7c99a69..0997154 100644 (file)
@@ -2895,6 +2895,13 @@ public:
     CORINFO_CLASS_HANDLE impGetStringClass();
     CORINFO_CLASS_HANDLE impGetObjectClass();
 
+    // Returns underlying type of handles returned by ldtoken instruction
+    inline var_types GetRuntimeHandleUnderlyingType()
+    {
+        // RuntimeTypeHandle is backed by raw pointer on CoreRT and by object reference on other runtimes
+        return IsTargetAbi(CORINFO_CORERT_ABI) ? TYP_I_IMPL : TYP_REF;
+    }
+
     //=========================================================================
     //                          PROTECTED
     //=========================================================================
index 90d1618..ddee0ab 100644 (file)
@@ -14236,7 +14236,7 @@ void Compiler::impImportBlockCode(BasicBlock* block)
                     op1 = gtNewHelperCallNode(CORINFO_HELP_TYPEHANDLE_TO_RUNTIMETYPE_MAYBENULL, TYP_STRUCT, helperArgs);
 
                     // The handle struct is returned in register
-                    op1->gtCall.gtReturnType = TYP_REF;
+                    op1->gtCall.gtReturnType = GetRuntimeHandleUnderlyingType();
 
                     tiRetVal = typeInfo(TI_STRUCT, impGetTypeHandleClass());
                 }
@@ -14276,7 +14276,7 @@ void Compiler::impImportBlockCode(BasicBlock* block)
                 op1 = gtNewHelperCallNode(helper, TYP_STRUCT, helperArgs);
 
                 // The handle struct is returned in register
-                op1->gtCall.gtReturnType = TYP_REF;
+                op1->gtCall.gtReturnType = GetRuntimeHandleUnderlyingType();
 
                 tiRetVal = verMakeTypeInfo(tokenType);
                 impPushOnStack(op1, tiRetVal);