Fix bugs related to MULTINEWARRAY in various backends

This commit is contained in:
Alexey Andreev 2022-07-10 18:16:16 +03:00
parent 2c74f282c4
commit 29fd95be95
5 changed files with 30 additions and 12 deletions

View File

@ -198,11 +198,7 @@ public class ClassGenerator {
@Override @Override
public void visit(ConstructMultiArrayInstruction insn) { public void visit(ConstructMultiArrayInstruction insn) {
ValueType type = insn.getItemType(); addType(insn.getItemType());
for (int i = 0; i < insn.getDimensions().size(); ++i) {
type = ValueType.arrayOf(type);
}
addType(type);
} }
}; };

View File

@ -1326,7 +1326,7 @@ class WasmGenerationVisitor implements StatementVisitor, ExprVisitor {
WasmInt32Subtype.INT32)); WasmInt32Subtype.INT32));
} }
int classPointer = classGenerator.getClassPointer(ValueType.arrayOf(type)); int classPointer = classGenerator.getClassPointer(type);
String allocName = context.names.forMethod(new MethodReference(Allocator.class, "allocateMultiArray", String allocName = context.names.forMethod(new MethodReference(Allocator.class, "allocateMultiArray",
RuntimeClass.class, Address.class, int.class, RuntimeArray.class)); RuntimeClass.class, Address.class, int.class, RuntimeArray.class));
WasmCall call = new WasmCall(allocName); WasmCall call = new WasmCall(allocName);

View File

@ -828,11 +828,7 @@ public class ClassInference {
@Override @Override
public void visit(ConstructMultiArrayInstruction insn) { public void visit(ConstructMultiArrayInstruction insn) {
ValueType type = insn.getItemType(); addType(insn.getReceiver().getIndex(), 0, insn.getItemType().toString());
for (int i = 0; i < insn.getDimensions().size(); ++i) {
type = ValueType.arrayOf(type);
}
addType(insn.getReceiver().getIndex(), 0, type.toString());
} }
@Override @Override

View File

@ -260,7 +260,7 @@ public class TypeInferer {
@Override @Override
public void createArray(VariableReader receiver, ValueType itemType, public void createArray(VariableReader receiver, ValueType itemType,
List<? extends VariableReader> dimensions) { List<? extends VariableReader> dimensions) {
types[receiver.getIndex()] = convert(ValueType.arrayOf(itemType)); types[receiver.getIndex()] = convert(itemType);
} }
@Override @Override

View File

@ -42,6 +42,32 @@ public class VMTest {
assertEquals(int[].class, array[0].getClass()); assertEquals(int[].class, array[0].getClass());
} }
@Test
public void longMultiArrayCreated() {
long[][] array = new long[3][2];
assertEquals(3, array.length);
assertEquals(2, array[1].length);
assertEquals(2, array[2].length);
for (int i = 0; i < array.length; ++i) {
assertEquals(2, array[i].length);
for (int j = 0; j < array[i].length; ++j) {
assertEquals(0, array[i][j]);
}
}
for (int i = 0; i < array.length; ++i) {
Arrays.fill(array[i], 0x0123456789ABCDEFL);
}
for (int i = 0; i < array.length; ++i) {
assertEquals(2, array[i].length);
for (int j = 0; j < array[i].length; ++j) {
assertEquals(0x0123456789ABCDEFL, array[i][j]);
}
}
}
@Test @Test
public void catchExceptionFromLambda() { public void catchExceptionFromLambda() {
try { try {