mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #9760 from ethereum/sol2YulStorageArrayIndexAccessFix
[Sol->Yul] Fixing storage array index access
This commit is contained in:
commit
202332405f
@ -1198,10 +1198,9 @@ string YulUtilFunctions::storageArrayIndexAccessFunction(ArrayType const& _type)
|
||||
slot := array
|
||||
}
|
||||
<!isBytesArray>
|
||||
let itemsPerSlot := div(0x20, <storageBytes>)
|
||||
let dataArea := <dataAreaFunc>(array)
|
||||
slot := add(dataArea, div(index, itemsPerSlot))
|
||||
offset := mod(index, itemsPerSlot)
|
||||
slot := add(dataArea, div(index, <itemsPerSlot>))
|
||||
offset := mul(mod(index, <itemsPerSlot>), <storageBytes>)
|
||||
</isBytesArray>
|
||||
<!multipleItemsPerSlot>
|
||||
let dataArea := <dataAreaFunc>(array)
|
||||
@ -1217,6 +1216,7 @@ string YulUtilFunctions::storageArrayIndexAccessFunction(ArrayType const& _type)
|
||||
("isBytesArray", _type.isByteArray())
|
||||
("storageSize", _type.baseType()->storageSize().str())
|
||||
("storageBytes", toString(_type.baseType()->storageBytes()))
|
||||
("itemsPerSlot", to_string(32 / _type.baseType()->storageBytes()))
|
||||
.render();
|
||||
});
|
||||
}
|
||||
|
@ -12,5 +12,7 @@ contract c {
|
||||
}
|
||||
}
|
||||
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// test() -> 1, 2, 3, 4
|
||||
|
@ -0,0 +1,16 @@
|
||||
contract C {
|
||||
uint8[33] a;
|
||||
uint32[9] b;
|
||||
uint120[3] c;
|
||||
|
||||
function f() public returns (uint8, uint32, uint120) {
|
||||
a[32] = 1; a[31] = 2; a[30] = 3;
|
||||
b[0] = 1; b[1] = 2; b[2] = 3;
|
||||
c[2] = 3; c[1] = 1;
|
||||
return (a[32], b[1], c[2]);
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f() -> 1, 2, 3
|
Loading…
Reference in New Issue
Block a user