From 591f9a63de7c378091459dd7778269733aab0ec7 Mon Sep 17 00:00:00 2001 From: Brezae Vlad Date: Thu, 16 Sep 2021 23:31:52 +0300 Subject: [PATCH] [interp] Disable optimization if the var index is greater than G_MAXUINT16 We store the var index in the guint16 slots of the instruction --- src/mono/mono/mini/interp/transform.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/mono/mono/mini/interp/transform.c b/src/mono/mono/mini/interp/transform.c index 952cfa5dd0cbb..637ccafb77e40 100644 --- a/src/mono/mono/mini/interp/transform.c +++ b/src/mono/mono/mini/interp/transform.c @@ -9288,8 +9288,8 @@ interp_alloc_offsets (TransformData *td) if (ins->flags & INTERP_INST_FLAG_CALL) { int *call_args = ins->info.call_args; if (call_args) { - int pair_sregs [MINT_MOV_PAIRS_MAX]; - int pair_dregs [MINT_MOV_PAIRS_MAX]; + guint16 pair_sregs [MINT_MOV_PAIRS_MAX]; + guint16 pair_dregs [MINT_MOV_PAIRS_MAX]; int num_pairs = 0; int var = *call_args; @@ -9303,9 +9303,10 @@ interp_alloc_offsets (TransformData *td) td->locals [new_var].flags |= INTERP_LOCAL_FLAG_CALL_ARGS; int mt = mint_type (td->locals [var].type); - if (mt != MINT_TYPE_VT && num_pairs < MINT_MOV_PAIRS_MAX) { - pair_sregs [num_pairs] = var; - pair_dregs [num_pairs] = new_var; + if (mt != MINT_TYPE_VT && num_pairs < MINT_MOV_PAIRS_MAX && var <= G_MAXUINT16 && new_var <= G_MAXUINT16) { + // We store these in the instruction data slots so we do this optimizations only if they fit + pair_sregs [num_pairs] = (guint16)var; + pair_dregs [num_pairs] = (guint16)new_var; num_pairs++; // The arg of the call is no longer global *call_args = new_var;