Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVlad Brezae <brezaevlad@gmail.com>2022-01-04 19:49:27 +0300
committerGitHub <noreply@github.com>2022-01-04 19:49:27 +0300
commita791978a6e4312698137be451c648b650a8c8663 (patch)
tree873aa91cc10316fabd34ecca45d69fc436fdc59b
parent16b53fa04c9824cda209b35febdc51b4876fd1a0 (diff)
[interp] Remove hack for nint/nfloat (#21382)
These structures are valuetypes, but their mint_type is a primitive. This means that a LDFLD applied on the type would have attempted to do a pointer dereference, because it saw that the current top of stack is not STACK_TYPE_VT. This was fixed in the past by passing the managed pointer to the valuetype rather than the valuetype itself, against the normal call convention, which lead to inconsistencies in the code. This commit removes that hack and fixes the problem by ignoring LDFLD applied to nint/nfloat valuetypes in the first place.
-rw-r--r--mono/mini/interp/transform.c45
1 files changed, 9 insertions, 36 deletions
diff --git a/mono/mini/interp/transform.c b/mono/mini/interp/transform.c
index 64e2d96d0d2..d07244ad441 100644
--- a/mono/mini/interp/transform.c
+++ b/mono/mini/interp/transform.c
@@ -1494,21 +1494,6 @@ interp_method_get_header (MonoMethod* method, MonoError *error)
return mono_method_get_header_internal (method, error);
}
-/* stores top of stack as local and pushes address of it on stack */
-static void
-emit_store_value_as_local (TransformData *td, MonoType *src)
-{
- int local = create_interp_local (td, mini_native_type_replace_type (src));
-
- store_local (td, local);
-
- interp_add_ins (td, MINT_LDLOCA_S);
- push_simple_type (td, STACK_TYPE_MP);
- interp_ins_set_dreg (td->last_ins, td->sp [-1].local);
- interp_ins_set_sreg (td->last_ins, local);
- td->locals [local].indirects++;
-}
-
static gboolean
interp_ip_in_cbb (TransformData *td, int il_offset)
{
@@ -1800,15 +1785,15 @@ interp_handle_magic_type_intrinsics (TransformData *td, MonoMethod *target_metho
int src_size = mini_magic_type_size (NULL, src);
int dst_size = mini_magic_type_size (NULL, dst);
- gboolean store_value_as_local = FALSE;
+ gboolean managed_fallback = FALSE;
switch (type_index) {
case 0: case 1:
if (!mini_magic_is_int_type (src) || !mini_magic_is_int_type (dst)) {
if (mini_magic_is_int_type (src))
- store_value_as_local = TRUE;
+ managed_fallback = TRUE;
else if (mono_class_is_magic_float (src_klass))
- store_value_as_local = TRUE;
+ managed_fallback = TRUE;
else
return FALSE;
}
@@ -1816,21 +1801,17 @@ interp_handle_magic_type_intrinsics (TransformData *td, MonoMethod *target_metho
case 2:
if (!mini_magic_is_float_type (src) || !mini_magic_is_float_type (dst)) {
if (mini_magic_is_float_type (src))
- store_value_as_local = TRUE;
+ managed_fallback = TRUE;
else if (mono_class_is_magic_int (src_klass))
- store_value_as_local = TRUE;
+ managed_fallback = TRUE;
else
return FALSE;
}
break;
}
- if (store_value_as_local) {
- emit_store_value_as_local (td, src);
-
- /* emit call to managed conversion method */
+ if (managed_fallback)
return FALSE;
- }
if (src_size > dst_size) { // 8 -> 4
switch (type_index) {
@@ -1887,15 +1868,6 @@ interp_handle_magic_type_intrinsics (TransformData *td, MonoMethod *target_metho
td->ip += 5;
return TRUE;
} else if (!strcmp ("CompareTo", tm) || !strcmp ("Equals", tm)) {
- MonoType *arg = csignature->params [0];
- int mt = mint_type (arg);
-
- /* on 'System.n*::{CompareTo,Equals} (System.n*)' variant we need to push managed
- * pointer instead of value */
- if (mt != MINT_TYPE_O)
- emit_store_value_as_local (td, arg);
-
- /* emit call to managed conversion method */
return FALSE;
} else if (!strcmp (".cctor", tm)) {
return FALSE;
@@ -2515,8 +2487,7 @@ interp_method_check_inlining (TransformData *td, MonoMethod *method, MonoMethodS
if (method->wrapper_type != MONO_WRAPPER_NONE)
return FALSE;
- /* Our usage of `emit_store_value_as_local ()` for nint, nuint and nfloat
- * is kinda hacky, and doesn't work with the inliner */
+ // FIXME Re-enable this
if (mono_class_get_magic_index (method->klass) >= 0)
return FALSE;
@@ -5595,6 +5566,8 @@ generate_code (TransformData *td, MonoMethod *method, MonoMethodHeader *header,
td->sp--;
interp_emit_sfld_access (td, field, field_klass, mt, TRUE, error);
goto_if_nok (error, exit);
+ } else if (td->sp [-1].type != STACK_TYPE_O && td->sp [-1].type != STACK_TYPE_MP && (mono_class_is_magic_int (klass) || mono_class_is_magic_float (klass))) {
+ // No need to load anything, the value is already on the execution stack
} else if (td->sp [-1].type == STACK_TYPE_VT) {
/* First we pop the vt object from the stack. Then we push the field */
int opcode = MINT_LDFLD_VT_I1 + mt - MINT_TYPE_I1;