Skip to content

Commit cbd97cc

Browse files
committed
Add some tests
1 parent 170526b commit cbd97cc

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
contract CollisionTest {
2+
uint256 y = 42;
3+
4+
function getArray() internal returns (uint256[10][1] storage x) {
5+
assembly {
6+
x.slot := sub(0, 1)
7+
}
8+
}
9+
10+
function f() public returns (uint256[10] memory) {
11+
uint256[10][1] storage x = getArray();
12+
for (uint i = 0; i < 10; i++)
13+
x[0][i] = i;
14+
delete x[0];
15+
return x[0];
16+
}
17+
18+
function g() public view returns (uint256) {
19+
return y;
20+
}
21+
}
22+
23+
// ----
24+
// g() -> 42
25+
// f() -> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
26+
// gas legacy: 170463
27+
// g() -> 0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
contract C {
2+
function f() public returns (uint256[10] memory) {
3+
uint256[10][1] storage x;
4+
assembly { x.slot := sub(0, 1) }
5+
for (uint i = 0; i < 10; i++)
6+
x[0][i] = i;
7+
x[0] = [11, 12, 13];
8+
return x[0];
9+
}
10+
}
11+
// ----
12+
// f() -> 11, 12, 13, 0, 0, 0, 0, 0, 0, 0
13+
// gas irOptimized: 181920
14+
// gas legacy: 200268
15+
// gas legacyOptimized: 181899
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
contract C layout at 2**256 - 1 {
2+
3+
function getArray() internal returns (uint256[10][1] storage x) {
4+
assembly {
5+
x.slot := sub(0, 1)
6+
}
7+
}
8+
9+
function f() public returns (uint256[10] memory) {
10+
uint256[10][1] storage x = getArray();
11+
for (uint i = 0; i < 10; i++)
12+
x[0][i] = i;
13+
delete x[0];
14+
return x[0];
15+
}
16+
}
17+
18+
// ----
19+
// f() -> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
20+
// gas legacy: 184143

0 commit comments

Comments
 (0)