Skip to content

Commit 61a1c77

Browse files
committed
Disable the type check on reference type array stores.
* method-to-ir.c (emit_array_store): We can avoid the type check on stores to reference arrays as it turns out List<T> is not covariant to its element type as I previously thought so.
1 parent 7c3708d commit 61a1c77

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

mono/mini/method-to-ir.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -4302,9 +4302,9 @@ generic_class_is_reference_type (MonoCompile *cfg, MonoClass *klass)
43024302
}
43034303

43044304
static MonoInst*
4305-
emit_array_store (MonoCompile *cfg, MonoClass *klass, MonoInst **sp, gboolean bounds_check)
4305+
emit_array_store (MonoCompile *cfg, MonoClass *klass, MonoInst **sp, gboolean safety_checks)
43064306
{
4307-
if (generic_class_is_reference_type (cfg, klass) &&
4307+
if (safety_checks && generic_class_is_reference_type (cfg, klass) &&
43084308
!(sp [2]->opcode == OP_PCONST && sp [2]->inst_p0 == NULL)) {
43094309
MonoClass *obj_array = mono_array_class_get_cached (mono_defaults.object_class, 1);
43104310
MonoMethod *helper = mono_marshal_get_virtual_stelemref (obj_array);
@@ -4331,11 +4331,11 @@ emit_array_store (MonoCompile *cfg, MonoClass *klass, MonoInst **sp, gboolean bo
43314331
int index_reg = sp [1]->dreg;
43324332
int offset = (mono_class_array_element_size (klass) * sp [1]->inst_c0) + G_STRUCT_OFFSET (MonoArray, vector);
43334333

4334-
if (bounds_check)
4334+
if (safety_checks)
43354335
MONO_EMIT_BOUNDS_CHECK (cfg, array_reg, MonoArray, max_length, index_reg);
43364336
EMIT_NEW_STORE_MEMBASE_TYPE (cfg, ins, &klass->byval_arg, array_reg, offset, sp [2]->dreg);
43374337
} else {
4338-
MonoInst *addr = mini_emit_ldelema_1_ins (cfg, klass, sp [0], sp [1], bounds_check);
4338+
MonoInst *addr = mini_emit_ldelema_1_ins (cfg, klass, sp [0], sp [1], safety_checks);
43394339
EMIT_NEW_STORE_MEMBASE_TYPE (cfg, ins, &klass->byval_arg, addr->dreg, 0, sp [2]->dreg);
43404340
}
43414341
return ins;

0 commit comments

Comments
 (0)