Skip to content

Commit

Permalink
[mono] Extend mono_gsharedvt_constrained_call for static calls and ha…
Browse files Browse the repository at this point in the history
…ndle nullable value types (dotnet#94787)

* [mono] Don't use this_arg in static constrained calls. Don't deref gsharedvt ref arguments if it is a nullable vtype.

* [mono] Fix lint formatting

* [mono] Remove additional deref register
  • Loading branch information
kotlarmilos authored Dec 7, 2023
1 parent ecf9bd4 commit 5b0f743
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
6 changes: 4 additions & 2 deletions src/mono/mono/mini/jit-icalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -1450,7 +1450,8 @@ mono_gsharedvt_constrained_call (gpointer mp, MonoMethod *cmethod, MonoClass *kl
break;
case MONO_GSHAREDVT_CONSTRAINT_CALL_TYPE_REF:
/* Calling a ref method with a ref receiver */
this_arg = *(gpointer*)mp;
/* Static calls don't have this arg */
this_arg = m_method_is_static (cmethod) ? NULL : *(gpointer*)mp;
m = info->method;
break;
default:
Expand Down Expand Up @@ -1482,7 +1483,8 @@ mono_gsharedvt_constrained_call (gpointer mp, MonoMethod *cmethod, MonoClass *kl
g_assert (fsig->param_count < 16);
memcpy (new_args, args, fsig->param_count * sizeof (gpointer));
for (int i = 0; i < fsig->param_count; ++i) {
if (deref_args [i])
// If the argument is not a vtype or nullable, deref it
if (deref_args [i] != MONO_GSHAREDVT_BOX_TYPE_VTYPE && deref_args [i] != MONO_GSHAREDVT_BOX_TYPE_NULLABLE)
new_args [i] = *(gpointer*)new_args [i];
}
args = new_args;
Expand Down
7 changes: 1 addition & 6 deletions src/mono/mono/mini/method-to-ir.c
Original file line number Diff line number Diff line change
Expand Up @@ -3896,13 +3896,8 @@ handle_constrained_gsharedvt_call (MonoCompile *cfg, MonoMethod *cmethod, MonoMe
int addr_reg;

if (mini_is_gsharedvt_type (fsig->params [i])) {
MonoInst *is_deref;
int deref_arg_reg;
ins = mini_emit_get_gsharedvt_info_klass (cfg, mono_class_from_mono_type_internal (fsig->params [i]), MONO_RGCTX_INFO_CLASS_BOX_TYPE);
deref_arg_reg = alloc_preg (cfg);
/* deref_arg = BOX_TYPE != MONO_GSHAREDVT_BOX_TYPE_VTYPE */
EMIT_NEW_BIALU_IMM (cfg, is_deref, OP_ISUB_IMM, deref_arg_reg, ins->dreg, 1);
MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STOREI1_MEMBASE_REG, is_gsharedvt_ins->dreg, i, is_deref->dreg);
MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STOREI1_MEMBASE_REG, is_gsharedvt_ins->dreg, i, ins->dreg);
} else if (has_gsharedvt) {
MONO_EMIT_NEW_STORE_MEMBASE_IMM (cfg, OP_STOREI1_MEMBASE_IMM, is_gsharedvt_ins->dreg, i, 0);
}
Expand Down

0 comments on commit 5b0f743

Please sign in to comment.