Skip to content

Commit

Permalink
Add more complete type check for stelem_ref_unchecked
Browse files Browse the repository at this point in the history
  • Loading branch information
kg committed Apr 11, 2024
1 parent 6492933 commit b1116ef
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/mono/mono/mini/interp/transform.c
Original file line number Diff line number Diff line change
Expand Up @@ -4813,11 +4813,20 @@ 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?
if (m_class_is_sealed (array_element_klass) &&
m_class_is_sealed (value_var_klass)) {
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 (td->verbose_level > 2)
g_printf (
"MINT_STELEM_REF_UNCHECKED for %s in %s::%s\n",
Expand Down

0 comments on commit b1116ef

Please sign in to comment.