Fix Yul codegen when dynamic array is used as rhs of assignment

This commit is contained in:
Leonardo Alt
2020-03-20 17:52:51 +01:00
parent d55bbd4aa5
commit 0fcb1427c9
5 changed files with 62 additions and 1 deletions
@@ -0,0 +1,14 @@
contract C {
function f(uint n) public pure returns (uint) {
uint[][] memory a = new uint[][](2);
for (uint i = 0; i < 2; ++i)
a[i] = new uint[](3);
a[1][1] = n;
uint[] memory b = a[1];
return b[1];
}
}
// ====
// compileViaYul: also
// ----
// f(uint256): 42 -> 42
@@ -0,0 +1,12 @@
contract C {
function f(uint n) public pure returns (uint) {
uint[][] memory a = new uint[][](2);
for (uint i = 0; i < 2; ++i)
a[i] = new uint[](3);
return a[0][0] = n;
}
}
// ====
// compileViaYul: also
// ----
// f(uint256): 42 -> 42
@@ -0,0 +1,19 @@
contract C {
function f(uint n) public pure returns (uint) {
uint[][][] memory a = new uint[][][](2);
for (uint i = 0; i < 2; ++i)
{
a[i] = new uint[][](3);
for (uint j = 0; j < 3; ++j)
a[i][j] = new uint[](4);
}
a[1][1][1] = n;
uint[][] memory b = a[1];
uint[] memory c = b[1];
return c[1];
}
}
// ====
// compileViaYul: also
// ----
// f(uint256): 42 -> 42
@@ -0,0 +1,16 @@
contract C {
function f(uint n) public pure returns (uint) {
uint[][][] memory a = new uint[][][](2);
for (uint i = 0; i < 2; ++i)
{
a[i] = new uint[][](3);
for (uint j = 0; j < 3; ++j)
a[i][j] = new uint[](4);
}
return a[1][1][1] = n;
}
}
// ====
// compileViaYul: also
// ----
// f(uint256): 42 -> 42