mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
[Sol->Yul] Fixing storage array index access
This commit is contained in:
parent
0b0c814b49
commit
ec6d21cde2
@ -1198,10 +1198,9 @@ string YulUtilFunctions::storageArrayIndexAccessFunction(ArrayType const& _type)
|
|||||||
slot := array
|
slot := array
|
||||||
}
|
}
|
||||||
<!isBytesArray>
|
<!isBytesArray>
|
||||||
let itemsPerSlot := div(0x20, <storageBytes>)
|
|
||||||
let dataArea := <dataAreaFunc>(array)
|
let dataArea := <dataAreaFunc>(array)
|
||||||
slot := add(dataArea, div(index, itemsPerSlot))
|
slot := add(dataArea, div(index, <itemsPerSlot>))
|
||||||
offset := mod(index, itemsPerSlot)
|
offset := mul(mod(index, <itemsPerSlot>), <storageBytes>)
|
||||||
</isBytesArray>
|
</isBytesArray>
|
||||||
<!multipleItemsPerSlot>
|
<!multipleItemsPerSlot>
|
||||||
let dataArea := <dataAreaFunc>(array)
|
let dataArea := <dataAreaFunc>(array)
|
||||||
@ -1217,6 +1216,7 @@ string YulUtilFunctions::storageArrayIndexAccessFunction(ArrayType const& _type)
|
|||||||
("isBytesArray", _type.isByteArray())
|
("isBytesArray", _type.isByteArray())
|
||||||
("storageSize", _type.baseType()->storageSize().str())
|
("storageSize", _type.baseType()->storageSize().str())
|
||||||
("storageBytes", toString(_type.baseType()->storageBytes()))
|
("storageBytes", toString(_type.baseType()->storageBytes()))
|
||||||
|
("itemsPerSlot", to_string(32 / _type.baseType()->storageBytes()))
|
||||||
.render();
|
.render();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -12,5 +12,7 @@ contract c {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ====
|
||||||
|
// compileViaYul: also
|
||||||
// ----
|
// ----
|
||||||
// test() -> 1, 2, 3, 4
|
// 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