Skip to content

Commit

Permalink
[jit] Fix the class of the stack entry for ldelema, it should be the …
Browse files Browse the repository at this point in the history
…class not its element class.

Fixes mono#10101.
  • Loading branch information
vargaz committed Feb 21, 2019
1 parent 7f01742 commit d1e8872
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
36 changes: 29 additions & 7 deletions mono/mini/arrays.cs
Expand Up @@ -525,7 +525,7 @@ class RefClass {
size = -1;
try {
res = new float [size];
} catch (OverflowException e) {
} catch (OverflowException) {

} catch (Exception) {
return 1;
Expand All @@ -536,7 +536,7 @@ class RefClass {
size = -2147483648;
try {
res = new float [size];
} catch (OverflowException e) {
} catch (OverflowException) {

} catch (Exception) {
return 3;
Expand Down Expand Up @@ -620,7 +620,7 @@ class RefClass {
size = -1;
try {
res = new float [dym_size, size];
} catch (OverflowException e) {
} catch (OverflowException) {

} catch (Exception) {
return 1;
Expand All @@ -631,7 +631,7 @@ class RefClass {
size = -2147483648;
try {
res = new float [size, dym_size];
} catch (OverflowException e) {
} catch (OverflowException) {

} catch (Exception) {
return 3;
Expand Down Expand Up @@ -786,7 +786,7 @@ public struct TestStruct {
try {
var arr = new byte[l];
return false;
} catch (Exception e) {
} catch (Exception) {
return true;
}
}
Expand Down Expand Up @@ -840,8 +840,30 @@ private unsafe static void WritePtr (FooStruct *val, out FooStruct* ptr)
return i;
}

return 0;
return 0;
}
}

class JaggedClass {
public int[][] a;

public JaggedClass () {
a = new int[][]{
new int[]{1,2,3},
new int[]{4,5,6},
new int[]{7,8,9}
};
}
}

public static int test_4_ref_jagged_array () {
var f = new JaggedClass ();

ref int[] r = ref f.a[1];

return r [0];
}

public static int bar (ref int[] x) {
return x [0];
}
}
4 changes: 2 additions & 2 deletions mono/mini/method-to-ir.c
Expand Up @@ -3976,7 +3976,7 @@ mini_emit_ldelema_1_ins (MonoCompile *cfg, MonoClass *klass, MonoInst *arr, Mono
static const int fast_log2 [] = { 1, 0, 1, -1, 2, -1, -1, -1, 3 };

EMIT_NEW_X86_LEA (cfg, ins, array_reg, index2_reg, fast_log2 [size], MONO_STRUCT_OFFSET (MonoArray, vector));
ins->klass = m_class_get_element_class (klass);
ins->klass = klass;
ins->type = STACK_MP;

return ins;
Expand All @@ -3999,7 +3999,7 @@ mini_emit_ldelema_1_ins (MonoCompile *cfg, MonoClass *klass, MonoInst *arr, Mono
}
MONO_EMIT_NEW_BIALU (cfg, OP_PADD, add_reg, array_reg, mult_reg);
NEW_BIALU_IMM (cfg, ins, OP_PADD_IMM, add_reg, add_reg, MONO_STRUCT_OFFSET (MonoArray, vector));
ins->klass = m_class_get_element_class (klass);
ins->klass = klass;
ins->type = STACK_MP;
MONO_ADD_INS (cfg->cbb, ins);

Expand Down

0 comments on commit d1e8872

Please sign in to comment.