Skip to content

Commit 30775c0

Browse files
authored
[mono][mini] Fix gshared crash when calling svm and constrained class is interface (#91667)
If constrained class is interface, then we don't need to do any vtable lookup, call interface method directly.
1 parent 68dd900 commit 30775c0

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

src/mono/mono/mini/mini-generic-sharing.c

+20-14
Original file line numberDiff line numberDiff line change
@@ -2272,22 +2272,28 @@ instantiate_info (MonoMemoryManager *mem_manager, MonoRuntimeGenericContextInfoT
22722272

22732273
mono_class_setup_vtable (info->klass);
22742274
// FIXME: Check type load
2275-
if (mono_class_is_interface (iface_class)) {
2276-
gboolean variance_used;
2277-
ioffset = mono_class_interface_offset_with_variance (info->klass, iface_class, &variance_used);
2278-
g_assert (ioffset != -1);
2279-
} else {
2280-
ioffset = 0;
2281-
}
2282-
2283-
if (info->method->is_generic == 0 && mono_class_is_ginst (info->method->klass)) {
2284-
slot = mono_method_get_vtable_slot (((MonoMethodInflated*)(info->method))->declaring);
2275+
2276+
if (mono_class_is_interface (info->klass)) {
2277+
// If constrained class is interface, we don't learn anything new by constraining
2278+
method = info->method;
22852279
} else {
2286-
slot = mono_method_get_vtable_slot (info->method);
2280+
if (mono_class_is_interface (iface_class)) {
2281+
gboolean variance_used;
2282+
ioffset = mono_class_interface_offset_with_variance (info->klass, iface_class, &variance_used);
2283+
g_assert (ioffset != -1);
2284+
} else {
2285+
ioffset = 0;
2286+
}
2287+
2288+
if (info->method->is_generic == 0 && mono_class_is_ginst (info->method->klass)) {
2289+
slot = mono_method_get_vtable_slot (((MonoMethodInflated*)(info->method))->declaring);
2290+
} else {
2291+
slot = mono_method_get_vtable_slot (info->method);
2292+
}
2293+
g_assert (slot != -1);
2294+
g_assert (m_class_get_vtable (info->klass));
2295+
method = m_class_get_vtable (info->klass) [ioffset + slot];
22872296
}
2288-
g_assert (slot != -1);
2289-
g_assert (m_class_get_vtable (info->klass));
2290-
method = m_class_get_vtable (info->klass) [ioffset + slot];
22912297

22922298
if (info->method->is_inflated) {
22932299
MonoGenericContext *method_ctx = mono_method_get_context (info->method);

0 commit comments

Comments
 (0)