Skip to content

Commit 7bb5629

Browse files
committed
Add more complete type check for stelem_ref_unchecked
1 parent a2f3773 commit 7bb5629

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4751,11 +4751,20 @@ handle_stelem (TransformData *td, int op)
47514751
*value_var_klass = mono_class_from_mono_type_internal (value_var->type);
47524752

47534753
if (m_class_is_array (array_var_klass)) {
4754+
ERROR_DECL (error);
47544755
MonoClass *array_element_klass = m_class_get_element_class (array_var_klass);
47554756
// If lhs is T[] and rhs is T and T is sealed, we can skip the runtime typecheck
47564757
// FIXME: right now this passes for Object[][] since Array is sealed, should it?
4757-
if (m_class_is_sealed (array_element_klass) &&
4758-
m_class_is_sealed (value_var_klass)) {
4758+
gboolean isinst;
4759+
// Make sure lhs and rhs element types are compatible, even though they usually would be
4760+
mono_class_is_assignable_from_checked (array_element_klass, value_var_klass, &isinst, error);
4761+
mono_error_cleanup (error); // FIXME: do not swallow the error
4762+
if (isinst &&
4763+
// We already know lhs and rhs are compatible, so if they're both sealed they
4764+
// should be the same exactly
4765+
m_class_is_sealed (array_element_klass) &&
4766+
m_class_is_sealed (value_var_klass)
4767+
) {
47594768
if (td->verbose_level > 2)
47604769
g_printf (
47614770
"MINT_STELEM_REF_UNCHECKED for %s in %s::%s\n",

0 commit comments

Comments
 (0)