Skip to content

Commit

Permalink
Correctness fix and simplification for stelem_ref_unchecked
Browse files Browse the repository at this point in the history
  • Loading branch information
kg committed Apr 25, 2024
1 parent 5bc698d commit 4b30eb2
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions src/mono/mono/mini/interp/transform.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 4b30eb2

Please sign in to comment.