mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #10554 from ethereum/emptyBytesPushSol2Yul
[Sol->Yul] Implementing empty byte array push.
This commit is contained in:
commit
4861c9b8d1
@ -1339,19 +1339,27 @@ string YulUtilFunctions::storageArrayPushZeroFunction(ArrayType const& _type)
|
|||||||
{
|
{
|
||||||
solAssert(_type.location() == DataLocation::Storage, "");
|
solAssert(_type.location() == DataLocation::Storage, "");
|
||||||
solAssert(_type.isDynamicallySized(), "");
|
solAssert(_type.isDynamicallySized(), "");
|
||||||
solUnimplementedAssert(!_type.isByteArray(), "Byte Arrays not yet implemented!");
|
|
||||||
solUnimplementedAssert(_type.baseType()->storageBytes() <= 32, "Base type is not yet implemented.");
|
solUnimplementedAssert(_type.baseType()->storageBytes() <= 32, "Base type is not yet implemented.");
|
||||||
|
|
||||||
string functionName = "array_push_zero_" + _type.identifier();
|
string functionName = "array_push_zero_" + _type.identifier();
|
||||||
return m_functionCollector.createFunction(functionName, [&]() {
|
return m_functionCollector.createFunction(functionName, [&]() {
|
||||||
return Whiskers(R"(
|
return Whiskers(R"(
|
||||||
function <functionName>(array) -> slot, offset {
|
function <functionName>(array) -> slot, offset {
|
||||||
let oldLen := <fetchLength>(array)
|
<?isBytes>
|
||||||
if iszero(lt(oldLen, <maxArrayLength>)) { <panic>() }
|
let data := sload(array)
|
||||||
sstore(array, add(oldLen, 1))
|
let oldLen := <extractLength>(data)
|
||||||
|
<increaseBytesSize>(array, data, oldLen, add(oldLen, 1))
|
||||||
|
<!isBytes>
|
||||||
|
let oldLen := <fetchLength>(array)
|
||||||
|
if iszero(lt(oldLen, <maxArrayLength>)) { <panic>() }
|
||||||
|
sstore(array, add(oldLen, 1))
|
||||||
|
</isBytes>
|
||||||
slot, offset := <indexAccess>(array, oldLen)
|
slot, offset := <indexAccess>(array, oldLen)
|
||||||
})")
|
})")
|
||||||
("functionName", functionName)
|
("functionName", functionName)
|
||||||
|
("isBytes", _type.isByteArray())
|
||||||
|
("increaseBytesSize", _type.isByteArray() ? increaseByteArraySizeFunction(_type) : "")
|
||||||
|
("extractLength", _type.isByteArray() ? extractByteArrayLengthFunction() : "")
|
||||||
("panic", panicFunction())
|
("panic", panicFunction())
|
||||||
("fetchLength", arrayLengthFunction(_type))
|
("fetchLength", arrayLengthFunction(_type))
|
||||||
("indexAccess", storageArrayIndexAccessFunction(_type))
|
("indexAccess", storageArrayIndexAccessFunction(_type))
|
||||||
|
@ -22,6 +22,8 @@ contract C {
|
|||||||
return data[0];
|
return data[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// ====
|
||||||
|
// compileViaYul: also
|
||||||
// ----
|
// ----
|
||||||
// fromMemory() -> 0x00
|
// fromMemory() -> 0x00
|
||||||
// fromCalldata(bytes): 0x40, 0x60, 0x00, 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff -> 0x00
|
// fromCalldata(bytes): 0x40, 0x60, 0x00, 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff -> 0x00
|
||||||
|
@ -18,6 +18,8 @@ contract C {
|
|||||||
return array[index];
|
return array[index];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// ====
|
||||||
|
// compileViaYul: also
|
||||||
// ----
|
// ----
|
||||||
// l() -> 0
|
// l() -> 0
|
||||||
// g(uint256): 70 ->
|
// g(uint256): 70 ->
|
||||||
|
Loading…
Reference in New Issue
Block a user