Skip to content

Commit

Permalink
[interp] track valuetype stack for CEE_RET too (mono/mono#17968)
Browse files Browse the repository at this point in the history
[interp] track valuetype stack for CEE_RET too

Usually the stack depth is determined via basic block predecessors, but  that only works for forward branches.

Fixes mono/mono#17924



Commit migrated from mono/mono@4d0feff
  • Loading branch information
lewurm authored and monojenkins committed Nov 29, 2019
1 parent 05aaa7b commit 56dedd8
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/mono/mono/mini/iltests.il
Original file line number Diff line number Diff line change
Expand Up @@ -3308,6 +3308,56 @@ L_3:
ret
}

.method private hidebysig static valuetype [mscorlib]System.Nullable`1<int32> ret_some_vt(int32 val) cil managed
{
.maxstack 8
ldarg.0
newobj instance void valuetype [mscorlib]System.Nullable`1<int32>::.ctor(!0)
ldarg.0
ldc.i4.0
ble.s second_vt

ldarg.0
ldc.i4.s 40
add
newobj instance void valuetype [mscorlib]System.Nullable`1<int32>::.ctor(!0)
pop
ret

second_vt_2:
ldarg.0
ldc.i4.s 30
add
newobj instance void valuetype [mscorlib]System.Nullable`1<int32>::.ctor(!0)
ret

second_vt:
pop
br second_vt_2
}

// https://github.com/mono/mono/issues/17924
.method static public int32 test_0_vt_sp_tracking () cil managed
{
.maxstack 2
.locals init (valuetype [mscorlib]System.Nullable`1<int32> V_0)

ldc.i4.s 10
call valuetype [mscorlib]System.Nullable`1<int32> Tests::ret_some_vt(int32)
stloc.0
ldloca.s V_0
call instance !0 valuetype [mscorlib]System.Nullable`1<int32>::get_Value()
ldc.i4.s 10
bne.un.s wrong

ldc.i4.0
ret

wrong:
ldc.i4.1
ret
}

.method public hidebysig static int32 test_10_rconv_to_u8_ovf_un() cil managed
{
// Code size 20 (0x14)
Expand Down
2 changes: 2 additions & 0 deletions src/mono/mono/mini/interp/transform.c
Original file line number Diff line number Diff line change
Expand Up @@ -3835,13 +3835,15 @@ generate_code (TransformData *td, MonoMethod *method, MonoMethodHeader *header,
}
td->last_ins->data [0] = exit_profiling;
WRITE32_INS (td->last_ins, 1, &vt_size);
POP_VT (td, vt_size);
++td->ip;
} else {
if (vt_size == 0)
SIMPLE_OP(td, ult->type == MONO_TYPE_VOID ? MINT_RET_VOID : MINT_RET);
else {
interp_add_ins (td, MINT_RET_VT);
WRITE32_INS (td->last_ins, 0, &vt_size);
POP_VT (td, vt_size);
++td->ip;
}
}
Expand Down

0 comments on commit 56dedd8

Please sign in to comment.