Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
mono_class_inflate_generic_class_checked can return NULL
  • Loading branch information
kg committed Mar 12, 2024
commit 3747a12a64f82fa57f18b8bb2c15b464d05620be
7 changes: 6 additions & 1 deletion src/mono/mono/metadata/class.c
Original file line number Diff line number Diff line change
Expand Up @@ -6788,10 +6788,13 @@ mono_method_get_base_method (MonoMethod *method, gboolean definition, MonoError
if (mono_class_is_open_constructed_type (m_class_get_byval_arg (parent))) {
parent = mono_class_inflate_generic_class_checked (parent, generic_inst, error);
return_val_if_nok (error, NULL);
g_assert (parent);
}

if (mono_class_is_ginst (parent)) {
parent_inst = mono_class_get_context (parent);
parent = mono_class_get_generic_class (parent)->container_class;
g_assert (parent);
}

mono_class_setup_vtable (parent);
Expand All @@ -6811,6 +6814,7 @@ mono_method_get_base_method (MonoMethod *method, gboolean definition, MonoError
if (mono_class_is_open_constructed_type (m_class_get_byval_arg (klass))) {
klass = mono_class_inflate_generic_class_checked (klass, generic_inst, error);
return_val_if_nok (error, NULL);
g_assert (klass);

generic_inst = NULL;
}
Expand All @@ -6824,6 +6828,7 @@ mono_method_get_base_method (MonoMethod *method, gboolean definition, MonoError
if (generic_inst) {
klass = mono_class_inflate_generic_class_checked (klass, generic_inst, error);
return_val_if_nok (error, NULL);
g_assert (klass);
generic_inst = NULL;
}

Expand Down Expand Up @@ -6912,7 +6917,7 @@ mono_class_has_default_constructor (MonoClass *klass, gboolean public_only)
* \param klass class in which the failure was detected
* \param fmt \c printf -style error message string.
*
* Sets a deferred failure in the class and prints a warning message.
* Sets a deferred failure in the class and prints a warning message.
* The deferred failure allows the runtime to attempt setting up the class layout at runtime.
*
* LOCKING: Acquires the loader lock.
Expand Down
7 changes: 7 additions & 0 deletions src/mono/mono/mini/aot-compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -5851,12 +5851,14 @@ add_generic_class_with_depth (MonoAotCompile *acfg, MonoClass *klass, int depth,

icomparable_inst = mono_class_inflate_generic_class_checked (icomparable, &ctx, error);
mono_error_assert_ok (error); /* FIXME don't swallow the error */
g_assert (icomparable_inst);
Comment on lines 5852 to +5854
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really wish we could teach CodeQL that for some functions that have a MonoError * argument, that if is_ok (error) then the return value is non-null. Otherwise these kinds of assertions are pretty lame.


if (mono_class_is_assignable_from_internal (icomparable_inst, tclass)) {
MonoClass *gcomparer_inst;
gcomparer = mono_class_load_from_name (mono_defaults.corlib, "System.Collections.Generic", "GenericComparer`1");
gcomparer_inst = mono_class_inflate_generic_class_checked (gcomparer, &ctx, error);
mono_error_assert_ok (error); /* FIXME don't swallow the error */
g_assert (gcomparer_inst);

add_generic_class (acfg, gcomparer_inst, FALSE, "Comparer<T>");
}
Expand All @@ -5878,13 +5880,15 @@ add_generic_class_with_depth (MonoAotCompile *acfg, MonoClass *klass, int depth,

iface_inst = mono_class_inflate_generic_class_checked (iface, &ctx, error);
mono_error_assert_ok (error); /* FIXME don't swallow the error */
g_assert (iface_inst);

if (mono_class_is_assignable_from_internal (iface_inst, tclass)) {
MonoClass *gcomparer_inst;

gcomparer = mono_class_load_from_name (mono_defaults.corlib, "System.Collections.Generic", "GenericEqualityComparer`1");
gcomparer_inst = mono_class_inflate_generic_class_checked (gcomparer, &ctx, error);
mono_error_assert_ok (error); /* FIXME don't swallow the error */
g_assert (gcomparer_inst);
add_generic_class (acfg, gcomparer_inst, FALSE, "EqualityComparer<T>");
}
}
Expand All @@ -5906,6 +5910,7 @@ add_generic_class_with_depth (MonoAotCompile *acfg, MonoClass *klass, int depth,
enum_comparer = mono_class_load_from_name (mono_defaults.corlib, "System.Collections.Generic", "EnumEqualityComparer`1");
enum_comparer_inst = mono_class_inflate_generic_class_checked (enum_comparer, &ctx, error);
mono_error_assert_ok (error); /* FIXME don't swallow the error */
g_assert (enum_comparer_inst);
add_generic_class (acfg, enum_comparer_inst, FALSE, "EqualityComparer<T>");
}
}
Expand All @@ -5927,6 +5932,7 @@ add_generic_class_with_depth (MonoAotCompile *acfg, MonoClass *klass, int depth,
comparer = mono_class_load_from_name (mono_defaults.corlib, "System.Collections.Generic", "ObjectComparer`1");
comparer_inst = mono_class_inflate_generic_class_checked (comparer, &ctx, error);
mono_error_assert_ok (error); /* FIXME don't swallow the error */
g_assert (comparer_inst);
add_generic_class (acfg, comparer_inst, FALSE, "Comparer<T>");
}
}
Expand All @@ -5950,6 +5956,7 @@ add_instances_of (MonoAotCompile *acfg, MonoClass *klass, MonoType **insts, int
ctx.class_inst = mono_metadata_get_generic_inst (1, args);
generic_inst = mono_class_inflate_generic_class_checked (klass, &ctx, error);
mono_error_assert_ok (error); /* FIXME don't swallow the error */
g_assert (generic_inst);
add_generic_class (acfg, generic_inst, force, "");
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/mono/mono/mini/mini-generic-sharing.c
Original file line number Diff line number Diff line change
Expand Up @@ -1308,6 +1308,7 @@ get_wrapper_shared_vtype (MonoType *t)

MonoClass *tuple_inst = mono_class_inflate_generic_class_checked (tuple_class, &ctx, error);
mono_error_assert_ok (error);
g_assert (tuple_inst);

//printf ("T: %s\n", mono_class_full_name (tuple_inst));

Expand Down Expand Up @@ -1407,6 +1408,7 @@ get_wrapper_shared_type_full (MonoType *t, gboolean is_field)
}
klass = mono_class_inflate_generic_class_checked (mono_class_get_generic_class (klass)->container_class, &ctx, error);
mono_error_assert_ok (error); /* FIXME don't swallow the error */
g_assert (klass);

t = m_class_get_byval_arg (klass);
MonoType *shared_type = get_wrapper_shared_vtype (t);
Expand Down Expand Up @@ -4345,6 +4347,7 @@ get_shared_type (MonoType *t, MonoType *type)

k = mono_class_inflate_generic_class_checked (gclass->container_class, &context, error);
mono_error_assert_ok (error); /* FIXME don't swallow the error */
g_assert (k);

return mini_get_shared_gparam (t, m_class_get_byval_arg (k));
} else if (MONO_TYPE_ISSTRUCT (type)) {
Expand Down
1 change: 1 addition & 0 deletions src/mono/mono/mini/mini.c
Original file line number Diff line number Diff line change
Expand Up @@ -4322,6 +4322,7 @@ mini_handle_call_res_devirt (MonoMethod *cmethod)

inst = mono_class_inflate_generic_class_checked (mono_class_get_iequatable_class (), &ctx, error);
mono_error_assert_ok (error);
g_assert (inst);

// EqualityComparer<T>.Default returns specific types depending on T
// FIXME: Special case more types: byte, string, nullable, enum ?
Expand Down
Loading