Skip to content

Commit 4b30eb2

Browse files
committed
Correctness fix and simplification for stelem_ref_unchecked
1 parent 5bc698d commit 4b30eb2

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
@@ -4816,20 +4816,16 @@ handle_stelem (TransformData *td, int op)
48164816
*value_var_klass = mono_class_from_mono_type_internal (value_var->type);
48174817

48184818
if (m_class_is_array (array_var_klass)) {
4819-
ERROR_DECL (error);
48204819
MonoClass *array_element_klass = m_class_get_element_class (array_var_klass);
48214820
// If lhs is T[] and rhs is T and T is sealed, we can skip the runtime typecheck
4822-
// FIXME: right now this passes for Object[][] since Array is sealed, should it?
4823-
gboolean isinst;
4824-
// Make sure lhs and rhs element types are compatible, even though they usually would be
4825-
mono_class_is_assignable_from_checked (array_element_klass, value_var_klass, &isinst, error);
4826-
mono_error_cleanup (error); // FIXME: do not swallow the error
4827-
if (isinst &&
4828-
// We already know lhs and rhs are compatible, so if they're both sealed they
4829-
// should be the same exactly
4830-
m_class_is_sealed (array_element_klass) &&
4831-
m_class_is_sealed (value_var_klass)
4832-
) {
4821+
if (
4822+
(array_element_klass == value_var_klass) &&
4823+
m_class_is_sealed(value_var_klass) &&
4824+
// HACK: Arrays are sealed, but it's possible to downcast string[][] to object[][],
4825+
// so we don't want to treat elements of array types as actually sealed.
4826+
// Our lhs of type object[][] might actually be of a different reference type.
4827+
!m_class_is_array(value_var_klass)
4828+
){
48334829
if (td->verbose_level > 2)
48344830
g_printf (
48354831
"MINT_STELEM_REF_UNCHECKED for %s in %s::%s\n",

0 commit comments

Comments
 (0)