From 4b30eb2d7e2ae1714f38b5b8a2113ee22b5c0cc5 Mon Sep 17 00:00:00 2001 From: Katelyn Gadd Date: Tue, 9 Apr 2024 13:21:24 -0700 Subject: [PATCH] Correctness fix and simplification for stelem_ref_unchecked --- src/mono/mono/mini/interp/transform.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/mono/mono/mini/interp/transform.c b/src/mono/mono/mini/interp/transform.c index 1492a8dae7d8e..d1fa661ae1fe2 100644 --- a/src/mono/mono/mini/interp/transform.c +++ b/src/mono/mono/mini/interp/transform.c @@ -4816,20 +4816,16 @@ handle_stelem (TransformData *td, int op) *value_var_klass = mono_class_from_mono_type_internal (value_var->type); if (m_class_is_array (array_var_klass)) { - ERROR_DECL (error); MonoClass *array_element_klass = m_class_get_element_class (array_var_klass); // If lhs is T[] and rhs is T and T is sealed, we can skip the runtime typecheck - // FIXME: right now this passes for Object[][] since Array is sealed, should it? - gboolean isinst; - // Make sure lhs and rhs element types are compatible, even though they usually would be - mono_class_is_assignable_from_checked (array_element_klass, value_var_klass, &isinst, error); - mono_error_cleanup (error); // FIXME: do not swallow the error - if (isinst && - // We already know lhs and rhs are compatible, so if they're both sealed they - // should be the same exactly - m_class_is_sealed (array_element_klass) && - m_class_is_sealed (value_var_klass) - ) { + if ( + (array_element_klass == value_var_klass) && + m_class_is_sealed(value_var_klass) && + // HACK: Arrays are sealed, but it's possible to downcast string[][] to object[][], + // so we don't want to treat elements of array types as actually sealed. + // Our lhs of type object[][] might actually be of a different reference type. + !m_class_is_array(value_var_klass) + ){ if (td->verbose_level > 2) g_printf ( "MINT_STELEM_REF_UNCHECKED for %s in %s::%s\n",