Skip to content

Commit 419f8e7

Browse files
committed
Correctness fix and simplification for stelem_ref_unchecked
1 parent 4e4a0b0 commit 419f8e7

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

src/mono/mono/mini/interp/transform.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4796,20 +4796,16 @@ handle_stelem (TransformData *td, int op)
47964796
*value_var_klass = mono_class_from_mono_type_internal (value_var->type);
47974797

47984798
if (m_class_is_array (array_var_klass)) {
4799-
ERROR_DECL (error);
48004799
MonoClass *array_element_klass = m_class_get_element_class (array_var_klass);
48014800
// If lhs is T[] and rhs is T and T is sealed, we can skip the runtime typecheck
4802-
// FIXME: right now this passes for Object[][] since Array is sealed, should it?
4803-
gboolean isinst;
4804-
// Make sure lhs and rhs element types are compatible, even though they usually would be
4805-
mono_class_is_assignable_from_checked (array_element_klass, value_var_klass, &isinst, error);
4806-
mono_error_cleanup (error); // FIXME: do not swallow the error
4807-
if (isinst &&
4808-
// We already know lhs and rhs are compatible, so if they're both sealed they
4809-
// should be the same exactly
4810-
m_class_is_sealed (array_element_klass) &&
4811-
m_class_is_sealed (value_var_klass)
4812-
) {
4801+
if (
4802+
(array_element_klass == value_var_klass) &&
4803+
m_class_is_sealed(value_var_klass) &&
4804+
// HACK: Arrays are sealed, but it's possible to downcast string[][] to object[][],
4805+
// so we don't want to treat elements of array types as actually sealed.
4806+
// Our lhs of type object[][] might actually be of a different reference type.
4807+
!m_class_is_array(value_var_klass)
4808+
){
48134809
if (td->verbose_level > 2)
48144810
g_printf (
48154811
"MINT_STELEM_REF_UNCHECKED for %s in %s::%s\n",

0 commit comments

Comments
 (0)