-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c7db606
commit 6644a74
Showing
10 changed files
with
453 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
test/cmdlineTests/mcopy_bytes_array_returned_from_function/args
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--evm-version cancun --no-cbor-metadata --via-ir --optimize --ir --debug-info none |
10 changes: 10 additions & 0 deletions
10
test/cmdlineTests/mcopy_bytes_array_returned_from_function/input.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
pragma solidity >=0.0.0; | ||
|
||
contract C { | ||
function foo() external pure returns (bytes memory) | ||
{ | ||
bytes memory ret = "aaaaa"; | ||
return ret; | ||
} | ||
} |
203 changes: 203 additions & 0 deletions
203
test/cmdlineTests/mcopy_bytes_array_returned_from_function/output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,203 @@ | ||
IR: | ||
|
||
/// @use-src 0:"mcopy_bytes_array_returned_from_function/input.sol" | ||
object "C_14" { | ||
code { | ||
|
||
mstore(64, memoryguard(128)) | ||
if callvalue() { revert_error_ca66f745a3ce8ff40e2ccaf1ad45db7774001b90d25810abd9040049be7bf4bb() } | ||
|
||
constructor_C_14() | ||
|
||
let _1 := allocate_unbounded() | ||
codecopy(_1, dataoffset("C_14_deployed"), datasize("C_14_deployed")) | ||
|
||
return(_1, datasize("C_14_deployed")) | ||
|
||
function allocate_unbounded() -> memPtr { | ||
memPtr := mload(64) | ||
} | ||
|
||
function revert_error_ca66f745a3ce8ff40e2ccaf1ad45db7774001b90d25810abd9040049be7bf4bb() { | ||
revert(0, 0) | ||
} | ||
|
||
function constructor_C_14() { | ||
|
||
} | ||
|
||
} | ||
/// @use-src 0:"mcopy_bytes_array_returned_from_function/input.sol" | ||
object "C_14_deployed" { | ||
code { | ||
|
||
mstore(64, memoryguard(128)) | ||
|
||
if iszero(lt(calldatasize(), 4)) | ||
{ | ||
let selector := shift_right_224_unsigned(calldataload(0)) | ||
switch selector | ||
|
||
case 0xc2985578 | ||
{ | ||
// foo() | ||
|
||
external_fun_foo_13() | ||
} | ||
|
||
default {} | ||
} | ||
|
||
revert_error_42b3090547df1d2001c96683413b8cf91c1b902ef5e3cb8d9f6f304cf7446f74() | ||
|
||
function shift_right_224_unsigned(value) -> newValue { | ||
newValue := | ||
|
||
shr(224, value) | ||
|
||
} | ||
|
||
function allocate_unbounded() -> memPtr { | ||
memPtr := mload(64) | ||
} | ||
|
||
function revert_error_ca66f745a3ce8ff40e2ccaf1ad45db7774001b90d25810abd9040049be7bf4bb() { | ||
revert(0, 0) | ||
} | ||
|
||
function revert_error_dbdddcbe895c83990c08b3492a0e83918d802a52331272ac6fdb6a7c4aea3b1b() { | ||
revert(0, 0) | ||
} | ||
|
||
function abi_decode_tuple_(headStart, dataEnd) { | ||
if slt(sub(dataEnd, headStart), 0) { revert_error_dbdddcbe895c83990c08b3492a0e83918d802a52331272ac6fdb6a7c4aea3b1b() } | ||
|
||
} | ||
|
||
function array_length_t_bytes_memory_ptr(value) -> length { | ||
|
||
length := mload(value) | ||
|
||
} | ||
|
||
function array_storeLengthForEncoding_t_bytes_memory_ptr_fromStack(pos, length) -> updated_pos { | ||
mstore(pos, length) | ||
updated_pos := add(pos, 0x20) | ||
} | ||
|
||
function copy_memory_to_memory_with_cleanup(src, dst, length) { | ||
mcopy(dst, src, length) | ||
mstore(add(dst, length), 0) | ||
} | ||
|
||
function round_up_to_mul_of_32(value) -> result { | ||
result := and(add(value, 31), not(31)) | ||
} | ||
|
||
function abi_encode_t_bytes_memory_ptr_to_t_bytes_memory_ptr_fromStack(value, pos) -> end { | ||
let length := array_length_t_bytes_memory_ptr(value) | ||
pos := array_storeLengthForEncoding_t_bytes_memory_ptr_fromStack(pos, length) | ||
copy_memory_to_memory_with_cleanup(add(value, 0x20), pos, length) | ||
end := add(pos, round_up_to_mul_of_32(length)) | ||
} | ||
|
||
function abi_encode_tuple_t_bytes_memory_ptr__to_t_bytes_memory_ptr__fromStack(headStart , value0) -> tail { | ||
tail := add(headStart, 32) | ||
|
||
mstore(add(headStart, 0), sub(tail, headStart)) | ||
tail := abi_encode_t_bytes_memory_ptr_to_t_bytes_memory_ptr_fromStack(value0, tail) | ||
|
||
} | ||
|
||
function external_fun_foo_13() { | ||
|
||
if callvalue() { revert_error_ca66f745a3ce8ff40e2ccaf1ad45db7774001b90d25810abd9040049be7bf4bb() } | ||
abi_decode_tuple_(4, calldatasize()) | ||
let ret_0 := fun_foo_13() | ||
let memPos := allocate_unbounded() | ||
let memEnd := abi_encode_tuple_t_bytes_memory_ptr__to_t_bytes_memory_ptr__fromStack(memPos , ret_0) | ||
return(memPos, sub(memEnd, memPos)) | ||
|
||
} | ||
|
||
function revert_error_42b3090547df1d2001c96683413b8cf91c1b902ef5e3cb8d9f6f304cf7446f74() { | ||
revert(0, 0) | ||
} | ||
|
||
function zero_value_for_split_t_bytes_memory_ptr() -> ret { | ||
ret := 96 | ||
} | ||
|
||
function panic_error_0x41() { | ||
mstore(0, 35408467139433450592217433187231851964531694900788300625387963629091585785856) | ||
mstore(4, 0x41) | ||
revert(0, 0x24) | ||
} | ||
|
||
function finalize_allocation(memPtr, size) { | ||
let newFreePtr := add(memPtr, round_up_to_mul_of_32(size)) | ||
// protect against overflow | ||
if or(gt(newFreePtr, 0xffffffffffffffff), lt(newFreePtr, memPtr)) { panic_error_0x41() } | ||
mstore(64, newFreePtr) | ||
} | ||
|
||
function allocate_memory(size) -> memPtr { | ||
memPtr := allocate_unbounded() | ||
finalize_allocation(memPtr, size) | ||
} | ||
|
||
function array_allocation_size_t_string_memory_ptr(length) -> size { | ||
// Make sure we can allocate memory without overflow | ||
if gt(length, 0xffffffffffffffff) { panic_error_0x41() } | ||
|
||
size := round_up_to_mul_of_32(length) | ||
|
||
// add length slot | ||
size := add(size, 0x20) | ||
|
||
} | ||
|
||
function allocate_memory_array_t_string_memory_ptr(length) -> memPtr { | ||
let allocSize := array_allocation_size_t_string_memory_ptr(length) | ||
memPtr := allocate_memory(allocSize) | ||
|
||
mstore(memPtr, length) | ||
|
||
} | ||
|
||
function store_literal_in_memory_5aff159202c5d82ecfd14de49cc2c8c1f74964a25d78c549137c4ce714030fe7(memPtr) { | ||
|
||
mstore(add(memPtr, 0), "aaaaa") | ||
|
||
} | ||
|
||
function copy_literal_to_memory_5aff159202c5d82ecfd14de49cc2c8c1f74964a25d78c549137c4ce714030fe7() -> memPtr { | ||
memPtr := allocate_memory_array_t_string_memory_ptr(5) | ||
store_literal_in_memory_5aff159202c5d82ecfd14de49cc2c8c1f74964a25d78c549137c4ce714030fe7(add(memPtr, 32)) | ||
} | ||
|
||
function convert_t_stringliteral_5aff159202c5d82ecfd14de49cc2c8c1f74964a25d78c549137c4ce714030fe7_to_t_bytes_memory_ptr() -> converted { | ||
converted := copy_literal_to_memory_5aff159202c5d82ecfd14de49cc2c8c1f74964a25d78c549137c4ce714030fe7() | ||
} | ||
|
||
function fun_foo_13() -> var__4_mpos { | ||
|
||
let zero_t_bytes_memory_ptr_1_mpos := zero_value_for_split_t_bytes_memory_ptr() | ||
var__4_mpos := zero_t_bytes_memory_ptr_1_mpos | ||
|
||
let var_ret_7_mpos := convert_t_stringliteral_5aff159202c5d82ecfd14de49cc2c8c1f74964a25d78c549137c4ce714030fe7_to_t_bytes_memory_ptr() | ||
|
||
let _2_mpos := var_ret_7_mpos | ||
let expr_10_mpos := _2_mpos | ||
|
||
var__4_mpos := expr_10_mpos | ||
leave | ||
|
||
} | ||
|
||
} | ||
|
||
data ".metadata" hex"" | ||
} | ||
|
||
} |
1 change: 1 addition & 0 deletions
1
test/cmdlineTests/mcopy_string_literal_returned_from_function/args
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--evm-version cancun --no-cbor-metadata --via-ir --optimize --ir --debug-info none |
9 changes: 9 additions & 0 deletions
9
test/cmdlineTests/mcopy_string_literal_returned_from_function/input.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
pragma solidity >=0.0.0; | ||
|
||
contract C { | ||
function foo() external pure returns (string memory) | ||
{ | ||
return "MCOPY on Cancun vacation."; | ||
} | ||
} |
Oops, something went wrong.