Skip to content

Commit a04bc0c

Browse files
authored
[mono][interp] Fix type of args when inlining method (#102801)
The vars allocated from pushing values on the execution stack might not reflect exactly the actual type of the var. Consider this pattern: condbr BB0 newobj Derived // push var0 of type Derived br BB1 BB0: newobj Base // push var1 of type Base // here we will end up inserting a `mov var1 -> var0` BB1: // top of stack will be seen as being var0 call Because we first reach BB1 with the stack contents of var0, BB1 will end up accessing top of the stack as var0. However the type of var0 at this point is not Derived, since it can also be a Base object. We currently don't update the type of var0, but just update the type information of the top of stack entry when entering BB1. When inlining, after this commit, we use the type information from the stack, rather than the type of the var present on the stack.
1 parent 26e8cc8 commit a04bc0c

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/mono/mono/mini/interp/transform.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4998,7 +4998,7 @@ generate_code (TransformData *td, MonoMethod *method, MonoMethodHeader *header,
49984998
arg_locals = (guint32*) g_malloc ((!!signature->hasthis + signature->param_count) * sizeof (guint32));
49994999
/* Allocate locals to store inlined method args from stack */
50005000
for (int i = signature->param_count - 1; i >= 0; i--) {
5001-
MonoType *type = td->locals [td->sp [-1].local].type;
5001+
MonoType *type = get_type_from_stack (td->sp [-1].type, td->sp [-1].klass);
50025002
local = create_interp_local (td, type);
50035003
arg_locals [i + !!signature->hasthis] = local;
50045004
store_local (td, local);

0 commit comments

Comments
 (0)