mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
[Sol->Yul] Implementing resizing of dynamic byte arrays
Co-authored-by: chriseth <chris@ethereum.org>
This commit is contained in:
co-authored by
chriseth
parent
9aafb62e52
commit
4a66723ff9
@@ -32,6 +32,7 @@ contract c {
|
||||
data.push(bytes1(i));
|
||||
}
|
||||
data.pop();
|
||||
data.pop();
|
||||
assembly {
|
||||
r := sload(data.slot)
|
||||
}
|
||||
@@ -42,4 +43,4 @@ contract c {
|
||||
// ----
|
||||
// test_short() -> 1780731860627700044960722568376587075150542249149356309979516913770823710
|
||||
// test_long() -> 67
|
||||
// test_pop() -> 1780731860627700044960722568376592200742329637303199754547598369979440702
|
||||
// test_pop() -> 1780731860627700044960722568376592200742329637303199754547598369979433020
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
contract C {
|
||||
bytes data;
|
||||
|
||||
function f() public returns (uint ret) {
|
||||
data.push("a");
|
||||
data.push("b");
|
||||
delete data;
|
||||
assembly {
|
||||
ret := sload(data.slot)
|
||||
}
|
||||
}
|
||||
|
||||
function g() public returns (uint ret) {
|
||||
assembly {
|
||||
sstore(data.slot, 67)
|
||||
}
|
||||
data.push("a");
|
||||
data.push("b");
|
||||
assert(data.length == 35);
|
||||
delete data;
|
||||
assert(data.length == 0);
|
||||
|
||||
uint size = 999;
|
||||
assembly {
|
||||
size := sload(data.slot)
|
||||
mstore(0, data.slot)
|
||||
ret := sload(keccak256(0, 32))
|
||||
}
|
||||
assert(size == 0);
|
||||
}
|
||||
}
|
||||
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f() -> 0
|
||||
// g() -> 0
|
||||
Reference in New Issue
Block a user