Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 940b332

Browse files
authored
[mini] Fix typo in mono_decompose_vtype_opts (#90825)
* Fix typo in mono_decompose_vtype_opts Without this, if some previous instruction already created a vreg for ins->dest (for example if we are doing multiple passes over the basic block because `restart == TRUE`) we will use an incorrect vreg when decomposing the current VMOVE Fixes #90800 * Only emit an OP_LDTOKEN_FIELD if we loaded a field token This is used by a CreateSpan optimization that needs access to the MonoClassField* For other cases of a bare LDTOKEN (such as hand-written IL that calls LDTOKEN on a type but doesn't follow it up with a call to `GetTypeFromHandle` leave the opcode as a VMOVE (from the `EMIT_NEW_TEMPLOAD` above))
1 parent 31234a8 commit 940b332

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/mono/mono/mini/decompose.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1226,7 +1226,7 @@ mono_decompose_vtype_opts (MonoCompile *cfg)
12261226
dest_var = get_vreg_to_inst (cfg, ins->dreg);
12271227

12281228
if (!src_var)
1229-
src_var = mono_compile_create_var_for_vreg (cfg, m_class_get_byval_arg (ins->klass), OP_LOCAL, ins->dreg);
1229+
src_var = mono_compile_create_var_for_vreg (cfg, m_class_get_byval_arg (ins->klass), OP_LOCAL, ins->sreg1);
12301230

12311231
if (!dest_var)
12321232
dest_var = mono_compile_create_var_for_vreg (cfg, m_class_get_byval_arg (ins->klass), OP_LOCAL, ins->dreg);

src/mono/mono/mini/method-to-ir.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10840,12 +10840,15 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b
1084010840
EMIT_NEW_TEMPLOADA (cfg, addr, vtvar->inst_c0);
1084110841
MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORE_MEMBASE_REG, addr->dreg, 0, ins->dreg);
1084210842
EMIT_NEW_TEMPLOAD (cfg, ins, vtvar->inst_c0);
10843-
ins->opcode = OP_LDTOKEN_FIELD;
10844-
ins->inst_c0 = n;
10845-
ins->inst_p1 = handle;
10843+
if (handle_class == mono_defaults.fieldhandle_class) {
10844+
ins->opcode = OP_LDTOKEN_FIELD;
10845+
ins->inst_c0 = n;
10846+
ins->inst_p1 = handle;
10847+
10848+
cfg->flags |= MONO_CFG_NEEDS_DECOMPOSE;
10849+
cfg->cbb->needs_decompose = TRUE;
10850+
}
1084610851

10847-
cfg->flags |= MONO_CFG_NEEDS_DECOMPOSE;
10848-
cfg->cbb->needs_decompose = TRUE;
1084910852
}
1085010853
}
1085110854

0 commit comments

Comments
 (0)