diff --git a/test/libsolidity/semanticTests/calldata/calldata_bytes_internal.sol b/test/libsolidity/semanticTests/calldata/calldata_bytes_internal.sol new file mode 100644 index 000000000..3b39a51a4 --- /dev/null +++ b/test/libsolidity/semanticTests/calldata/calldata_bytes_internal.sol @@ -0,0 +1,12 @@ +contract C { + function f(bytes calldata b, uint i) internal pure returns (byte) { + return b[i]; + } + function f(uint, bytes calldata b, uint) external pure returns (byte) { + return f(b, 2); + } +} +// ==== +// compileViaYul: also +// ---- +// f(uint256,bytes,uint256): 7, 0x60, 7, 4, "abcd" -> "c" diff --git a/test/libsolidity/semanticTests/calldata/calldata_internal_function_pointer.sol b/test/libsolidity/semanticTests/calldata/calldata_internal_function_pointer.sol new file mode 100644 index 000000000..539653219 --- /dev/null +++ b/test/libsolidity/semanticTests/calldata/calldata_internal_function_pointer.sol @@ -0,0 +1,17 @@ +contract C { + function(bytes calldata) returns (byte) x; + constructor() public { x = f; } + function f(bytes calldata b) internal pure returns (byte) { + return b[2]; + } + function h(bytes calldata b) external returns (byte) { + return x(b); + } + function g() external returns (byte) { + bytes memory a = new bytes(34); + a[2] = byte(uint8(7)); + return this.h(a); + } +} +// ---- +// g() -> 0x0700000000000000000000000000000000000000000000000000000000000000 diff --git a/test/libsolidity/semanticTests/calldata/calldata_internal_library.sol b/test/libsolidity/semanticTests/calldata/calldata_internal_library.sol new file mode 100644 index 000000000..90528fc70 --- /dev/null +++ b/test/libsolidity/semanticTests/calldata/calldata_internal_library.sol @@ -0,0 +1,22 @@ +library L { + function f(uint, bytes calldata _x, uint) internal returns (byte) { + return _x[2]; + } +} +contract C { + function f(bytes calldata a) + external + returns (byte) + { + return L.f(3, a, 9); + } + function g() public returns (byte) { + bytes memory x = new bytes(4); + x[2] = 0x08; + return this.f(x); + } +} +// ==== +// compileViaYul: also +// ---- +// g() -> 0x0800000000000000000000000000000000000000000000000000000000000000 diff --git a/test/libsolidity/semanticTests/calldata/calldata_internal_multi_array.sol b/test/libsolidity/semanticTests/calldata/calldata_internal_multi_array.sol new file mode 100644 index 000000000..6dea02b29 --- /dev/null +++ b/test/libsolidity/semanticTests/calldata/calldata_internal_multi_array.sol @@ -0,0 +1,23 @@ +pragma experimental ABIEncoderV2; + +contract C { + function g(uint[][2] calldata s) internal pure returns (uint, uint[] calldata) { + return (s[0][1], s[1]); + } + function f(uint, uint[][2] calldata s, uint) external pure returns (uint, uint) { + (uint x, uint[] calldata y) = g(s); + return (x, y[0]); + } + function g() public returns (uint, uint) { + uint[][2] memory x; + x[0] = new uint[](2); + x[1] = new uint[](2); + x[0][1] = 7; + x[1][0] = 8; + return this.f(4, x, 5); + } +} +// ==== +// compileViaYul: also +// ---- +// g() -> 7, 8 diff --git a/test/libsolidity/semanticTests/calldata/calldata_internal_multi_fixed_array.sol b/test/libsolidity/semanticTests/calldata/calldata_internal_multi_fixed_array.sol new file mode 100644 index 000000000..6fb892dde --- /dev/null +++ b/test/libsolidity/semanticTests/calldata/calldata_internal_multi_fixed_array.sol @@ -0,0 +1,19 @@ +contract C { + function g(uint[3][2] calldata s) internal pure returns (uint, uint[3] calldata) { + return (s[0][1], s[1]); + } + function f(uint, uint[3][2] calldata s, uint) external pure returns (uint, uint) { + (uint x, uint[3] calldata y) = g(s); + return (x, y[0]); + } + function g() public returns (uint, uint) { + uint[3][2] memory x; + x[0][1] = 7; + x[1][0] = 8; + return this.f(4, x, 5); + } +} +// ==== +// compileViaYul: also +// ---- +// g() -> 7, 8 diff --git a/test/libsolidity/semanticTests/calldata/calldata_memory_mixed.sol b/test/libsolidity/semanticTests/calldata/calldata_memory_mixed.sol new file mode 100644 index 000000000..a87afac11 --- /dev/null +++ b/test/libsolidity/semanticTests/calldata/calldata_memory_mixed.sol @@ -0,0 +1,21 @@ +contract C { + function f(bytes memory _a, bytes calldata _b, bytes memory _c) + public + returns (uint, byte, byte, byte) + { + return (_a.length + _b.length + _c.length, _a[1], _b[1], _c[1]); + } + function g() public returns (uint, byte, byte, byte) { + bytes memory x = new bytes(3); + bytes memory y = new bytes(4); + bytes memory z = new bytes(7); + x[1] = 0x08; + y[1] = 0x09; + z[1] = 0x0a; + return this.f(x, y, z); + } +} +// ==== +// compileViaYul: also +// ---- +// g() -> 0x0e, 0x0800000000000000000000000000000000000000000000000000000000000000, 0x0900000000000000000000000000000000000000000000000000000000000000, 0x0a00000000000000000000000000000000000000000000000000000000000000 diff --git a/test/libsolidity/semanticTests/calldata/calldata_struct_internal.sol b/test/libsolidity/semanticTests/calldata/calldata_struct_internal.sol new file mode 100644 index 000000000..a463b5d33 --- /dev/null +++ b/test/libsolidity/semanticTests/calldata/calldata_struct_internal.sol @@ -0,0 +1,17 @@ +pragma experimental ABIEncoderV2; + +struct S { + uint x; + uint y; +} + +contract C { + function f(S calldata s) internal pure returns (uint, uint) { + return (s.x, s.y); + } + function f(uint, S calldata s, uint) external pure returns (uint, uint) { + return f(s); + } +} +// ---- +// f(uint256,(uint256,uint256),uint256): 7, 1, 2, 4 -> 1, 2