mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
[Sol->Yul] Implementing member access to arrays in calldata structs.
This commit is contained in:
parent
5f732cb3ca
commit
bae32ac402
@ -1810,6 +1810,11 @@ void IRGeneratorForStatements::endVisit(MemberAccess const& _memberAccess)
|
|||||||
", " <<
|
", " <<
|
||||||
offset <<
|
offset <<
|
||||||
")\n";
|
")\n";
|
||||||
|
else if (
|
||||||
|
dynamic_cast<ArrayType const*>(_memberAccess.annotation().type) ||
|
||||||
|
dynamic_cast<StructType const*>(_memberAccess.annotation().type)
|
||||||
|
)
|
||||||
|
define(_memberAccess) << offset << "\n";
|
||||||
else
|
else
|
||||||
define(_memberAccess) <<
|
define(_memberAccess) <<
|
||||||
m_utils.readFromCalldata(*_memberAccess.annotation().type) <<
|
m_utils.readFromCalldata(*_memberAccess.annotation().type) <<
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
pragma abicoder v2;
|
pragma abicoder v2;
|
||||||
|
|
||||||
|
|
||||||
contract C {
|
contract C {
|
||||||
@ -19,6 +19,7 @@ contract C {
|
|||||||
c = s.c;
|
c = s.c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// ====
|
||||||
|
// compileViaYul: also
|
||||||
// ----
|
// ----
|
||||||
// f((uint256,uint256[2],uint256)): 42, 1, 2, 23 -> 42, 1, 2, 23
|
// f((uint256,uint256[2],uint256)): 42, 1, 2, 23 -> 42, 1, 2, 23
|
||||||
|
@ -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
|
@ -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
|
@ -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
|
@ -22,5 +22,7 @@ contract C {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ====
|
||||||
|
// compileViaYul: also
|
||||||
// ----
|
// ----
|
||||||
// f((uint256,uint256,(uint256,uint256),uint256)): 1, 2, 3, 4, 5 -> 1, 2, 3, 4, 5
|
// f((uint256,uint256,(uint256,uint256),uint256)): 1, 2, 3, 4, 5 -> 1, 2, 3, 4, 5
|
||||||
|
Loading…
Reference in New Issue
Block a user