mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Use .slot and .offest to access storage items.
This commit is contained in:
@@ -7,9 +7,9 @@ contract C {
|
||||
uint256 off1;
|
||||
uint256 off2;
|
||||
assembly {
|
||||
sstore(z_slot, 7)
|
||||
off1 := z_offset
|
||||
off2 := y_offset
|
||||
sstore(z.slot, 7)
|
||||
off1 := z.offset
|
||||
off2 := y.offset
|
||||
}
|
||||
assert(off1 == 0);
|
||||
assert(off2 == 2);
|
||||
|
||||
+2
-2
@@ -8,8 +8,8 @@ contract C {
|
||||
uint256 off2;
|
||||
assembly {
|
||||
function f() -> o1 {
|
||||
sstore(z_slot, 7)
|
||||
o1 := y_offset
|
||||
sstore(z.slot, 7)
|
||||
o1 := y.offset
|
||||
}
|
||||
off2 := f()
|
||||
}
|
||||
|
||||
+2
-2
@@ -10,8 +10,8 @@ contract C {
|
||||
Data storage x = a;
|
||||
uint256 off;
|
||||
assembly {
|
||||
sstore(x_slot, 7)
|
||||
off := x_offset
|
||||
sstore(x.slot, 7)
|
||||
off := x.offset
|
||||
}
|
||||
assert(off == 0);
|
||||
return true;
|
||||
|
||||
@@ -13,7 +13,7 @@ contract C {
|
||||
|
||||
bytes32 slot = keccak256(abi.encode(uint(1), uint(0)));
|
||||
assembly {
|
||||
_data_slot := slot
|
||||
_data.slot := slot
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user