- if (!context_used && (mini_class_has_reference_variant_generic_argument (cfg, klass, context_used) || klass->is_array_special_interface)) {
+ if (mini_class_has_reference_variant_generic_argument (cfg, klass, context_used) || klass->is_array_special_interface) {
+ MonoInst *args [3];
+ args [0] = source; /* obj */
+
+ if (context_used) {
+ MonoInst *cache_ins;
+
+ cache_ins = mini_emit_get_rgctx_klass (cfg, context_used, klass, MONO_RGCTX_INFO_CAST_CACHE);
+
+ /* klass - it's the second element of the cache entry*/
+ EMIT_NEW_LOAD_MEMBASE (cfg, args [1], OP_LOAD_MEMBASE, alloc_preg (cfg), cache_ins->dreg, sizeof (gpointer));
+
+ args [2] = cache_ins; /* cache */
+ } else {
+ int idx;
+
+ EMIT_NEW_CLASSCONST (cfg, args [1], klass); /* klass */
+
+ idx = get_castclass_cache_idx (cfg); /* inline cache*/
+ args [2] = mini_emit_runtime_constant (cfg, MONO_PATCH_INFO_CASTCLASS_CACHE, GINT_TO_POINTER (idx));
+ }