Merge remote-tracking branch 'origin/develop' into breaking

This commit is contained in:
chriseth
2020-11-17 18:51:57 +01:00
141 changed files with 2354 additions and 1203 deletions
@@ -0,0 +1,25 @@
contract c {
uint[9] m_data;
uint[] m_data_dyn;
uint8[][] m_byte_data;
function store(uint[9] calldata a, uint8[3][] calldata b) external returns (uint8) {
m_data = a;
m_data_dyn = a;
m_byte_data = b;
return b[3][1]; // note that access and declaration are reversed to each other
}
function retrieve() public returns (uint a, uint b, uint c, uint d, uint e, uint f, uint g) {
a = m_data.length;
b = m_data[7];
c = m_data_dyn.length;
d = m_data_dyn[7];
e = m_byte_data.length;
f = m_byte_data[3].length;
g = m_byte_data[3][1];
}
}
// ====
// compileViaYul: also
// ----
// store(uint256[9],uint8[3][]): 21, 22, 23, 24, 25, 26, 27, 28, 29, 0x140, 4, 1, 2, 3, 11, 12, 13, 21, 22, 23, 31, 32, 33 -> 32
// retrieve() -> 9, 28, 9, 28, 4, 3, 32
@@ -0,0 +1,25 @@
// Test to see if cleanup is performed properly during array copying
contract C {
uint128[] x;
function f() public returns(bool) {
x.push(42); x.push(42); x.push(42); x.push(42);
uint128[] memory y = new uint128[](1);
y[0] = 23;
x = y;
assembly { sstore(x.slot, 4) }
assert(x[0] == 23);
assert(x[1] == 0);
assert(x[2] == 0);
// Issue 9832: the cleanup was only performed for the first packed type leaving the rest of
// the slot dirty.
assert(x[3] == 0);
return true;
}
}
// ====
// compileViaYul: also
// ----
// f() -> true
@@ -0,0 +1,50 @@
// Issue 9832: Test to see if cleanup is performed properly after array copying
contract C {
uint40[] x;
function f() public returns(bool) {
x.push(42); x.push(42); x.push(42); x.push(42);
x.push(42); x.push(42); x.push(42); x.push(42);
x.push(42); x.push(42); x.push(42); x.push(42);
x.push(42); x.push(42); x.push(42); x.push(42);
x.push(42); x.push(42); x.push(42); x.push(42);
uint40[] memory y = new uint40[](1);
y[0] = 23;
x = y;
assembly { sstore(x.slot, 20) }
assert(x[0] == 23);
assert(x[1] == 0);
assert(x[2] == 0);
assert(x[3] == 0);
assert(x[4] == 0);
assert(x[5] == 0);
assert(x[6] == 0);
assert(x[7] == 0);
assert(x[8] == 0);
assert(x[9] == 0);
assert(x[10] == 0);
assert(x[11] == 0);
assert(x[12] == 0);
assert(x[13] == 0);
assert(x[14] == 0);
assert(x[15] == 0);
assert(x[16] == 0);
assert(x[17] == 0);
assert(x[18] == 0);
assert(x[19] == 0);
return true;
}
}
// ====
// compileViaYul: also
// ----
// f() -> true
@@ -0,0 +1,42 @@
contract c {
uint[3][90][] large;
uint[3][3][] small;
function test() public returns (uint r) {
for (uint i = 0; i < 7; i++) {
large.push();
small.push();
}
large[3][2][0] = 2;
large[1] = large[3];
small[3][2][0] = 2;
small[1] = small[2];
r = ((
small[3][2][0] * 0x100 |
small[1][2][0]) * 0x100 |
large[3][2][0]) * 0x100 |
large[1][2][0];
delete small;
delete large;
}
function clear() public returns (uint, uint) {
for (uint i = 0; i < 7; i++) {
large.push();
small.push();
}
small[3][2][0] = 0;
large[3][2][0] = 0;
while (small.length > 0)
small.pop();
while (large.length > 0)
large.pop();
return (small.length, large.length);
}
}
// ====
// compileViaYul: also
// ----
// test() -> 0x02000202
// storage: empty
// clear() -> 0, 0
// storage: empty
@@ -11,5 +11,7 @@ contract c {
}
}
// ====
// compileViaYul: also
// ----
// test(uint256[2][]): 32, 3, 7, 8, 9, 10, 11, 12 -> 10
@@ -0,0 +1,24 @@
contract c {
uint[] data1;
uint[] data2;
function setData1(uint length, uint index, uint value) public {
data1 = new uint[](length);
if (index < length)
data1[index] = value;
}
function copyStorageStorage() public { data2 = data1; }
function getData2(uint index) public returns (uint len, uint val) {
len = data2.length; if (index < len) val = data2[index];
}
}
// ====
// compileViaYul: also
// ----
// setData1(uint256,uint256,uint256): 10, 5, 4 ->
// copyStorageStorage() ->
// getData2(uint256): 5 -> 10, 4
// setData1(uint256,uint256,uint256): 0, 0, 0 ->
// copyStorageStorage() ->
// getData2(uint256): 0 -> 0, 0
// storage: empty
@@ -10,5 +10,7 @@ contract c {
}
}
// ====
// compileViaYul: also
// ----
// test() -> 9, 4
@@ -0,0 +1,22 @@
contract c {
struct Data { uint x; uint y; }
Data[] data1;
Data[] data2;
function test() public returns (uint x, uint y) {
while (data1.length < 9)
data1.push();
data1[8].x = 4;
data1[8].y = 5;
data2 = data1;
x = data2[8].x;
y = data2[8].y;
while (data1.length > 0)
data1.pop();
data2 = data1;
}
}
// ====
// compileViaYul: also
// ----
// test() -> 4, 5
// storage: empty
@@ -0,0 +1,19 @@
contract c {
byte[10] data1;
bytes2[32] data2;
function test() public returns (uint check, uint res1, uint res2) {
uint i;
for (i = 0; i < data2.length; ++i)
data2[i] = 0xffff;
check = uint(uint16(data2[31])) * 0x10000 | uint(uint16(data2[14]));
for (i = 0; i < data1.length; ++i)
data1[i] = byte(uint8(1 + i));
data2 = data1;
for (i = 0; i < 16; ++i)
res1 |= uint(uint16(data2[i])) * 0x10000**i;
for (i = 0; i < 16; ++i)
res2 |= uint(uint16(data2[16 + i])) * 0x10000**i;
}
}
// ----
// test() -> 0xffffffff, 0x0000000000000000000000000a00090008000700060005000400030002000100, 0x0000000000000000000000000000000000000000000000000000000000000000
@@ -0,0 +1,18 @@
contract Test {
uint24[] public data;
function set(uint24[] memory _data) public returns (uint) {
data = _data;
return data.length;
}
function get() public returns (uint24[] memory) {
return data;
}
}
// ====
// compileViaYul: also
// ----
// set(uint24[]): 0x20, 18, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 -> 18
// data(uint256): 7 -> 8
// data(uint256): 15 -> 16
// data(uint256): 18 -> FAILURE
// get() -> 0x20, 18, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18
@@ -0,0 +1,17 @@
contract c {
function set(uint key) public returns (bool) { data[key] = msg.data; return true; }
function copy(uint from, uint to) public returns (bool) { data[to] = data[from]; return true; }
mapping(uint => bytes) data;
}
// ====
// compileViaYul: also
// ----
// set(uint256): 1, 2 -> true
// set(uint256): 2, 2, 3, 4, 5 -> true
// storage: nonempty
// copy(uint256,uint256): 1, 2 -> true
// storage: nonempty
// copy(uint256,uint256): 99, 1 -> true
// storage: nonempty
// copy(uint256,uint256): 99, 2 -> true
// storage: empty
@@ -14,5 +14,7 @@ contract C {
}
}
// ====
// compileViaYul: also
// ----
// test() -> 7
@@ -0,0 +1,14 @@
contract c {
function set() public returns (bool) { data1 = msg.data; return true; }
function reset() public returns (bool) { data1 = data2; return true; }
bytes data1;
bytes data2;
}
// ====
// compileViaYul: also
// ----
// set(): 1, 2, 3, 4, 5 -> true
// storage: nonempty
// reset() -> true
// storage: empty