Make RyuJIT tolerate null CLASSID_RUNTIME_TYPE (#21331)
authorMichal Strehovský <MichalStrehovsky@users.noreply.github.com>
Mon, 3 Dec 2018 08:15:26 +0000 (09:15 +0100)
committerGitHub <noreply@github.com>
Mon, 3 Dec 2018 08:15:26 +0000 (09:15 +0100)
If we're compiling a class library that has no concept of reflection (and runtime types), EE cannot provide a class handle for this class. Make RyuJIT tolerant to null coming back.

src/jit/gentree.cpp

index cf1de87..56eea9d 100644 (file)
@@ -15162,7 +15162,7 @@ Compiler::TypeProducerKind Compiler::gtGetTypeProducerKind(GenTree* tree)
         bool                 isNonNull = false;
         CORINFO_CLASS_HANDLE clsHnd    = gtGetClassHandle(tree, &isExact, &isNonNull);
 
-        if (clsHnd == info.compCompHnd->getBuiltinClass(CLASSID_RUNTIME_TYPE))
+        if (clsHnd != NO_CLASS_HANDLE && clsHnd == info.compCompHnd->getBuiltinClass(CLASSID_RUNTIME_TYPE))
         {
             return TPK_Other;
         }
@@ -16373,9 +16373,11 @@ CORINFO_CLASS_HANDLE Compiler::gtGetClassHandle(GenTree* tree, bool* pIsExact, b
             if (intrinsic->gtIntrinsicId == CORINFO_INTRINSIC_Object_GetType)
             {
                 CORINFO_CLASS_HANDLE runtimeType = info.compCompHnd->getBuiltinClass(CLASSID_RUNTIME_TYPE);
-                objClass                         = runtimeType;
-                *pIsExact                        = false;
-                *pIsNonNull                      = true;
+                assert(runtimeType != NO_CLASS_HANDLE);
+
+                objClass    = runtimeType;
+                *pIsExact   = false;
+                *pIsNonNull = true;
             }
 
             break;
@@ -16528,6 +16530,8 @@ CORINFO_CLASS_HANDLE Compiler::gtGetHelperCallClassHandle(GenTreeCall* call, boo
             const bool           helperResultNonNull = (helper == CORINFO_HELP_TYPEHANDLE_TO_RUNTIMETYPE);
             CORINFO_CLASS_HANDLE runtimeType         = info.compCompHnd->getBuiltinClass(CLASSID_RUNTIME_TYPE);
 
+            assert(runtimeType != NO_CLASS_HANDLE);
+
             objClass    = runtimeType;
             *pIsNonNull = helperResultNonNull;
             break;