mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #9843 from ethereum/deleteStructSol2Yul
[Sol->Yul] Implementing delete struct
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
Error (1834): Unimplemented feature error: setToZero for type t_struct$_S_$4_storage not yet implemented! in FILENAME REMOVED
|
||||
--> yul_unimplemented/input.sol:9:9:
|
||||
Error (1834): Unimplemented feature error: Byte Arrays not yet implemented! in FILENAME REMOVED
|
||||
--> yul_unimplemented/input.sol:6:9:
|
||||
|
|
||||
9 | delete str;
|
||||
| ^^^^^^^^^^
|
||||
6 | delete a;
|
||||
| ^^^^^^^^
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.0;
|
||||
contract test {
|
||||
struct S {
|
||||
uint x;
|
||||
}
|
||||
S str;
|
||||
constructor() {
|
||||
delete str;
|
||||
bytes a;
|
||||
function f() public {
|
||||
delete a;
|
||||
}
|
||||
}
|
||||
@@ -16,5 +16,7 @@ contract C {
|
||||
}
|
||||
}
|
||||
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f() -> true # This code interprets x as an array length and thus will go out of gas. neither of the two should throw due to out-of-bounds access #
|
||||
|
||||
@@ -31,6 +31,8 @@ contract C {
|
||||
}
|
||||
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// l() -> 0
|
||||
// f(uint256): 42 ->
|
||||
|
||||
+2
@@ -18,6 +18,8 @@ contract C {
|
||||
}
|
||||
}
|
||||
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f() -> true
|
||||
// a() -> 7
|
||||
|
||||
@@ -21,5 +21,7 @@ contract C {
|
||||
return (s.f(), h(s));
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// g() -> 7, 7
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
contract C {
|
||||
struct S {
|
||||
uint16 v;
|
||||
S[] x;
|
||||
}
|
||||
uint8[77] padding;
|
||||
S s;
|
||||
constructor() {
|
||||
s.v = 21;
|
||||
s.x.push(); s.x.push(); s.x.push();
|
||||
s.x[0].v = 101; s.x[1].v = 102; s.x[2].v = 103;
|
||||
}
|
||||
function f() public returns (uint256 a, uint256 b, uint256 c, uint256 d) {
|
||||
S storage sptr1 = s.x[0];
|
||||
S storage sptr2 = s.x[1];
|
||||
S storage sptr3 = s.x[2];
|
||||
uint256 slot1; uint256 slot2; uint256 slot3;
|
||||
assembly { slot1 := sptr1.slot slot2 := sptr2.slot slot3 := sptr3.slot }
|
||||
delete s;
|
||||
assembly { a := sload(s.slot) b := sload(slot1) c := sload(slot2) d := sload(slot3) }
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f() -> 0, 0, 0, 0
|
||||
@@ -15,5 +15,7 @@ contract C {
|
||||
}
|
||||
}
|
||||
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f() -> 1
|
||||
|
||||
@@ -16,5 +16,7 @@ contract test {
|
||||
}
|
||||
}
|
||||
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// deleteMember() -> 0
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
contract C {
|
||||
struct S {
|
||||
uint256 x;
|
||||
uint128 y;
|
||||
uint32 z;
|
||||
}
|
||||
uint8 b = 23;
|
||||
S s;
|
||||
uint8 a = 17;
|
||||
function f() public {
|
||||
s.x = 42; s.y = 42; s.y = 42;
|
||||
delete s;
|
||||
assert(s.x == 0);
|
||||
assert(s.y == 0);
|
||||
assert(s.z == 0);
|
||||
assert(b == 23);
|
||||
assert(a == 17);
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f() ->
|
||||
@@ -0,0 +1,47 @@
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
contract C {
|
||||
struct S {
|
||||
uint128 a;
|
||||
uint256[] x;
|
||||
uint240 b;
|
||||
}
|
||||
uint8 b = 23;
|
||||
S s;
|
||||
uint8 a = 17;
|
||||
function f() public {
|
||||
delete s;
|
||||
s.x.push(42); s.x.push(42); s.x.push(42);
|
||||
delete s;
|
||||
assert(s.x.length == 0);
|
||||
uint256[] storage x = s.x;
|
||||
assembly { sstore(x.slot, 3) }
|
||||
assert(s.x[0] == 0);
|
||||
assert(s.x[1] == 0);
|
||||
assert(s.x[2] == 0);
|
||||
assert(b == 23);
|
||||
assert(a == 17);
|
||||
}
|
||||
|
||||
function g() public {
|
||||
delete s;
|
||||
s.x.push(42); s.x.push(42); s.x.push(42);
|
||||
s.a = 1; s.b = 2;
|
||||
delete s.x;
|
||||
assert(s.x.length == 0);
|
||||
uint256[] storage x = s.x;
|
||||
assembly { sstore(x.slot, 3) }
|
||||
assert(s.x[0] == 0);
|
||||
assert(s.x[1] == 0);
|
||||
assert(s.x[2] == 0);
|
||||
assert(b == 23);
|
||||
assert(a == 17);
|
||||
assert(s.a == 1);
|
||||
assert(s.b == 2);
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f() ->
|
||||
// g() ->
|
||||
@@ -14,5 +14,7 @@ contract test {
|
||||
}
|
||||
}
|
||||
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// deleteIt() -> 0
|
||||
|
||||
@@ -18,6 +18,8 @@ contract test {
|
||||
inner.recursive[0].z = inner.recursive[1].z + 1;
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// check() -> false
|
||||
// set() ->
|
||||
|
||||
@@ -22,5 +22,7 @@ contract C {
|
||||
}
|
||||
}
|
||||
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f() -> true
|
||||
|
||||
Reference in New Issue
Block a user