Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mono][interp] Allow passing vtypes with a single scalar field to nat… #79686

Merged
merged 1 commit into from
Dec 16, 2022
Merged
Changes from all commits
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
41 changes: 40 additions & 1 deletion src/mono/mono/mini/interp/transform.c
Original file line number Diff line number Diff line change
Expand Up @@ -2593,6 +2593,43 @@ interp_transform_internal_calls (MonoMethod *method, MonoMethod *target_method,
return target_method;
}

static gboolean
interp_type_as_ptr (MonoType *tp);

/* Return whenever TYPE represents a vtype with only one scalar member */
static gboolean
is_scalar_vtype (MonoType *type)
{
MonoClass *klass;
MonoClassField *field;
gpointer iter;

if (!MONO_TYPE_ISSTRUCT (type))
return FALSE;
klass = mono_class_from_mono_type_internal (type);
mono_class_init_internal (klass);

int size = mono_class_value_size (klass, NULL);
if (size == 0 || size > SIZEOF_VOID_P)
return FALSE;

iter = NULL;
int nfields = 0;
field = NULL;
while ((field = mono_class_get_fields_internal (klass, &iter))) {
if (field->type->attrs & FIELD_ATTRIBUTE_STATIC)
continue;
nfields ++;
if (nfields > 1)
return FALSE;
MonoType *t = mini_get_underlying_type (field->type);
if (!interp_type_as_ptr (t))
return FALSE;
}

return TRUE;
}

static gboolean
interp_type_as_ptr (MonoType *tp)
{
Expand All @@ -2603,7 +2640,7 @@ interp_type_as_ptr (MonoType *tp)
if ((tp)->type == MONO_TYPE_I4)
return TRUE;
#if SIZEOF_VOID_P == 8
if ((tp)->type == MONO_TYPE_I8)
if ((tp)->type == MONO_TYPE_I8 || (tp)->type == MONO_TYPE_U8)
return TRUE;
#endif
if ((tp)->type == MONO_TYPE_BOOLEAN)
Expand All @@ -2612,6 +2649,8 @@ interp_type_as_ptr (MonoType *tp)
return TRUE;
if ((tp)->type == MONO_TYPE_VALUETYPE && m_class_is_enumtype (tp->data.klass))
return TRUE;
if (is_scalar_vtype (tp))
return TRUE;
return FALSE;
}

Expand Down