[Sol->Yul] Implementing struct copying from memory to storage

This commit is contained in:
Djordje Mijovic
2020-09-02 12:28:53 +02:00
parent 5e66583b0b
commit b89c863e11
6 changed files with 108 additions and 18 deletions
@@ -4,15 +4,16 @@ contract C {
struct S {
uint256 a;
uint256 b;
bytes2 c;
}
function f(S calldata s) external pure returns (uint256, uint256) {
function f(S calldata s) external pure returns (uint256, uint256, byte) {
S memory m = s;
return (m.a, m.b);
return (m.a, m.b, m.c[1]);
}
}
// ====
// compileViaYul: also
// ----
// f((uint256,uint256)): 42, 23 -> 42, 23
// f((uint256,uint256, bytes2)): 42, 23, "ab" -> 42, 23, "b"
@@ -0,0 +1,28 @@
pragma experimental ABIEncoderV2;
contract C {
struct S {
uint32 a;
uint128 b;
uint256 c;
}
struct X {
uint256 a;
S s;
}
uint[79] r;
X x;
function f() external returns (uint32, uint128, uint256) {
X memory m = X(12, S(42, 23, 34));
x = m;
return (x.s.a, x.s.b, x.s.c);
}
}
// ====
// compileViaYul: also
// ----
// f() -> 42, 23, 34
@@ -10,5 +10,7 @@ contract C {
}
}
// ====
// compileViaYul: also
// ----
// s() -> 1, true