Skip to content

Commit 555789d

Browse files
authored
[mono] Fix runtime invokes to methods returning byref values in llvmonly mode. (#52501)
Fixes some System.Runtime test failures on wasm.
1 parent 607ecff commit 555789d

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

src/mono/mono/mini/mini-runtime.c

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3062,6 +3062,8 @@ create_runtime_invoke_info (MonoMethod *method, gpointer compiled_method, gboole
30623062
return ret;
30633063
}
30643064

3065+
static GENERATE_GET_CLASS_WITH_CACHE (nullbyrefreturn_ex, "Mono", "NullByRefReturnException");
3066+
30653067
static MonoObject*
30663068
mono_llvmonly_runtime_invoke (MonoMethod *method, RuntimeInvokeInfo *info, void *obj, void **params, MonoObject **exc, MonoError *error)
30673069
{
@@ -3130,11 +3132,29 @@ mono_llvmonly_runtime_invoke (MonoMethod *method, RuntimeInvokeInfo *info, void
31303132
if (exc && *exc)
31313133
return NULL;
31323134

3135+
if (sig->ret->byref) {
3136+
if (*(gpointer*)retval == NULL) {
3137+
MonoClass *klass = mono_class_get_nullbyrefreturn_ex_class ();
3138+
MonoObject *ex = mono_object_new_checked (klass, error);
3139+
mono_error_assert_ok (error);
3140+
mono_error_set_exception_instance (error, (MonoException*)ex);
3141+
return NULL;
3142+
}
3143+
}
3144+
31333145
if (sig->ret->type != MONO_TYPE_VOID) {
3134-
if (info->ret_box_class)
3135-
return mono_value_box_checked (info->ret_box_class, retval, error);
3136-
else
3137-
return *(MonoObject**)retval;
3146+
if (info->ret_box_class) {
3147+
if (sig->ret->byref) {
3148+
return mono_value_box_checked (info->ret_box_class, *(gpointer*)retval, error);
3149+
} else {
3150+
return mono_value_box_checked (info->ret_box_class, retval, error);
3151+
}
3152+
} else {
3153+
if (sig->ret->byref)
3154+
return **(MonoObject***)retval;
3155+
else
3156+
return *(MonoObject**)retval;
3157+
}
31383158
} else {
31393159
return NULL;
31403160
}

0 commit comments

Comments
 (0)