Merge pull request #9503 from ethereum/copyStructCalldataMemorySol2Yul

[Sol->Yul] Implementing struct copying from calldata to memory.
This commit is contained in:
Đorđe Mijović
2020-08-11 23:53:59 +02:00
committed by GitHub
3 changed files with 20 additions and 2 deletions
+16 -1
View File
@@ -1911,8 +1911,23 @@ string YulUtilFunctions::conversionFunction(Type const& _from, Type const& _to)
break;
}
case Type::Category::Struct:
solUnimplementedAssert(false, "Struct conversion not implemented.");
{
solAssert(toCategory == Type::Category::Struct, "");
auto const& fromStructType = dynamic_cast<StructType const &>(_from);
auto const& toStructType = dynamic_cast<StructType const &>(_to);
solAssert(fromStructType.structDefinition() == toStructType.structDefinition(), "");
solUnimplementedAssert(!fromStructType.isDynamicallyEncoded(), "");
solUnimplementedAssert(toStructType.location() == DataLocation::Memory, "");
solUnimplementedAssert(fromStructType.location() == DataLocation::CallData, "");
body = Whiskers(R"(
converted := <abiDecode>(value, calldatasize())
)")("abiDecode", ABIFunctions(m_evmVersion, m_revertStrings, m_functionCollector).tupleDecoder(
{&toStructType}
)).render();
break;
}
case Type::Category::FixedBytes:
{
FixedBytesType const& from = dynamic_cast<FixedBytesType const&>(_from);
@@ -1,6 +1,5 @@
pragma experimental ABIEncoderV2;
contract C {
struct S {
uint256 a;
@@ -13,5 +12,7 @@ contract C {
}
}
// ====
// compileViaYul: also
// ----
// f((uint256,uint256)): 42, 23 -> 42, 23
@@ -23,5 +23,7 @@ contract C {
}
}
// ====
// compileViaYul: also
// ----
// f((uint256,uint256,(uint256,uint256),uint256)): 1, 2, 3, 4, 5 -> 1, 2, 3, 4, 5