Merge pull request #11930 from ethereum/calldataStructInlineAssembly

Fix inline assembly assignments to calldata structs and statically-sized calldata arrays.
This commit is contained in:
chriseth
2021-09-14 16:16:48 +02:00
committed by GitHub
10 changed files with 111 additions and 25 deletions
@@ -0,0 +1,10 @@
contract C {
function f(uint[2][2] calldata x) public returns (uint[2][2] memory r) {
assembly { x := 0x24 }
r = x;
}
}
// ====
// compileViaYul: also
// ----
// f(uint256[2][2]): 0x0, 8, 7, 6, 5 -> 8, 7, 6, 5
@@ -0,0 +1,18 @@
pragma abicoder v2;
contract C {
struct S { uint256 x; }
struct S2 { uint256 x; uint256 y; }
function f(S calldata s, S2 calldata s2) public pure returns (uint256 r, uint256 r2) {
assembly {
s := s2
s2 := 4
}
r = s.x;
r2 = s2.x;
}
}
// ====
// compileViaYul: also
// ----
// f((uint256),(uint256,uint256)): 0x42, 0x07, 0x77 -> 0x07, 0x42
@@ -0,0 +1,23 @@
pragma abicoder v2;
contract C {
struct S { int8 x; int8 y; }
function f() internal pure returns(S calldata s) {
assembly {
s := 0x24
}
}
function g() public pure returns(int8, int8) {
S calldata s = f();
return (s.x, s.y);
}
function h() public pure returns(uint256) { f(); return 0x42; }
function i() public pure returns(uint256) { abi.decode(msg.data[4:], (S)); return 0x42; }
}
// ====
// compileViaYul: also
// ----
// g(): 0xCAFFEE, 0x42, 0x21 -> 0x42, 0x21
// g(): 0xCAFFEE, 0x4242, 0x2121 -> FAILURE
// g(): 0xCAFFEE, 0x42 -> 0x42, 0
// h() -> 0x42
// i() -> FAILURE
@@ -0,0 +1,5 @@
contract C {
function f() internal returns (uint256[] calldata) {}
}
// ----
// TypeError 3464: (48-66): This variable is of calldata pointer type and can be returned without prior assignment, which would lead to undefined behaviour.
@@ -0,0 +1,5 @@
contract C {
function f() internal returns (uint256[1] calldata) {}
}
// ----
// TypeError 3464: (48-67): This variable is of calldata pointer type and can be returned without prior assignment, which would lead to undefined behaviour.
@@ -0,0 +1,6 @@
contract C {
struct S { uint256 x; }
function f() internal returns (S calldata) {}
}
// ----
// TypeError 3464: (76-86): This variable is of calldata pointer type and can be returned without prior assignment, which would lead to undefined behaviour.