[Sol->Yul] Implementing member access to arrays in calldata structs.

This commit is contained in:
Djordje Mijovic 2020-11-26 11:18:01 +01:00
parent 5f732cb3ca
commit bae32ac402
6 changed files with 90 additions and 2 deletions

View File

@ -1810,6 +1810,11 @@ void IRGeneratorForStatements::endVisit(MemberAccess const& _memberAccess)
", " <<
offset <<
")\n";
else if (
dynamic_cast<ArrayType const*>(_memberAccess.annotation().type) ||
dynamic_cast<StructType const*>(_memberAccess.annotation().type)
)
define(_memberAccess) << offset << "\n";
else
define(_memberAccess) <<
m_utils.readFromCalldata(*_memberAccess.annotation().type) <<

View File

@ -1,4 +1,4 @@
pragma abicoder v2;
pragma abicoder v2;
contract C {
@ -19,6 +19,7 @@ contract C {
c = s.c;
}
}
// ====
// compileViaYul: also
// ----
// f((uint256,uint256[2],uint256)): 42, 1, 2, 23 -> 42, 1, 2, 23

View File

@ -0,0 +1,24 @@
pragma abicoder v2;
contract C {
struct S {
uint32 a;
uint256[] b;
uint64 c;
}
function f(S calldata s)
external
pure
returns (uint32 a, uint256 b0, uint256 b1, uint64 c)
{
a = s.a;
b0 = s.b[0];
b1 = s.b[1];
c = s.c;
}
}
// ====
// compileViaYul: also
// ----
// f((uint32,uint256[],uint64)): 0x20, 42, 0x60, 23, 2, 1, 2 -> 42, 1, 2, 23

View File

@ -0,0 +1,28 @@
pragma abicoder v2;
contract C {
struct S {
uint64 a;
uint64 b;
}
struct S1 {
uint256 a;
S s;
uint256 c;
}
function f(S1 calldata s1)
external
pure
returns (uint256 a, uint64 b0, uint64 b1, uint256 c)
{
a = s1.a;
b0 = s1.s.a;
b1 = s1.s.b;
c = s1.c;
}
}
// ====
// compileViaYul: also
// ----
// f((uint256,(uint64, uint64),uint256)): 42, 1, 2, 23 -> 42, 1, 2, 23

View File

@ -0,0 +1,28 @@
pragma abicoder v2;
contract C {
struct S {
uint64 a;
bytes b;
}
struct S1 {
uint256 a;
S s;
uint256 c;
}
function f(S1 calldata s1)
external
pure
returns (uint256 a, uint64 b0, byte b1, uint256 c)
{
a = s1.a;
b0 = s1.s.a;
b1 = s1.s.b[0];
c = s1.c;
}
}
// ====
// compileViaYul: also
// ----
// f((uint256,(uint64, bytes),uint256)): 0x20, 42, 0x60, 23, 1, 0x40, 2, "ab" -> 42, 1, "a", 23

View File

@ -22,5 +22,7 @@ contract C {
}
}
// ====
// compileViaYul: also
// ----
// f((uint256,uint256,(uint256,uint256),uint256)): 1, 2, 3, 4, 5 -> 1, 2, 3, 4, 5