From 143471fe8714e5360547f7fcda3793ad5ef7b19d Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 17 Dec 2019 13:41:56 +0100 Subject: [PATCH] Tests. --- .../functionSideEffects/mload_in_function.yul | 11 +++++++ .../fullSuite/abi_example1.yul | 19 ++++++------ .../loadResolver/mload_in_function.yul | 29 +++++++++++++++++++ 3 files changed, 50 insertions(+), 9 deletions(-) create mode 100644 test/libyul/functionSideEffects/mload_in_function.yul create mode 100644 test/libyul/yulOptimizerTests/loadResolver/mload_in_function.yul diff --git a/test/libyul/functionSideEffects/mload_in_function.yul b/test/libyul/functionSideEffects/mload_in_function.yul new file mode 100644 index 000000000..170535926 --- /dev/null +++ b/test/libyul/functionSideEffects/mload_in_function.yul @@ -0,0 +1,11 @@ +{ + function foo(x) { + for {} x { x := mload(0) mstore(0, 0)} {} + } + mstore(0, 1337) + foo(42) + sstore(0, mload(0)) +} +// ---- +// : invalidatesStorage, invalidatesMemory +// foo: invalidatesMemory diff --git a/test/libyul/yulOptimizerTests/fullSuite/abi_example1.yul b/test/libyul/yulOptimizerTests/fullSuite/abi_example1.yul index ab1ebb10d..0d37cf1b9 100644 --- a/test/libyul/yulOptimizerTests/fullSuite/abi_example1.yul +++ b/test/libyul/yulOptimizerTests/fullSuite/abi_example1.yul @@ -477,15 +477,16 @@ // pos := add(pos, 0x60) // } // let _3 := mload(64) -// if slt(sub(_3, length), 128) { revert(_1, _1) } -// let offset := calldataload(add(length, 64)) -// let _4 := 0xffffffffffffffff -// if gt(offset, _4) { revert(_1, _1) } -// let value2 := abi_decode_t_array$_t_uint256_$dyn_memory_ptr(add(length, offset), _3) -// let offset_1 := calldataload(add(length, 0x60)) -// if gt(offset_1, _4) { revert(_1, _1) } -// let value3 := abi_decode_t_array$_t_array$_t_uint256_$2_memory_$dyn_memory_ptr(add(length, offset_1), _3) -// sstore(calldataload(length), calldataload(add(length, 0x20))) +// let _4 := mload(0x20) +// if slt(sub(_3, _4), 128) { revert(_1, _1) } +// let offset := calldataload(add(_4, 64)) +// let _5 := 0xffffffffffffffff +// if gt(offset, _5) { revert(_1, _1) } +// let value2 := abi_decode_t_array$_t_uint256_$dyn_memory_ptr(add(_4, offset), _3) +// let offset_1 := calldataload(add(_4, 0x60)) +// if gt(offset_1, _5) { revert(_1, _1) } +// let value3 := abi_decode_t_array$_t_array$_t_uint256_$2_memory_$dyn_memory_ptr(add(_4, offset_1), _3) +// sstore(calldataload(_4), calldataload(add(_4, 0x20))) // sstore(value2, value3) // sstore(_1, pos) // } diff --git a/test/libyul/yulOptimizerTests/loadResolver/mload_in_function.yul b/test/libyul/yulOptimizerTests/loadResolver/mload_in_function.yul new file mode 100644 index 000000000..9bb8261dd --- /dev/null +++ b/test/libyul/yulOptimizerTests/loadResolver/mload_in_function.yul @@ -0,0 +1,29 @@ +{ + function foo(x) { + for {} x { x := mload(0) mstore(0, 0)} {} + } + mstore(0, 1337) + foo(42) + sstore(0, mload(0)) +} +// ==== +// step: loadResolver +// ---- +// { +// function foo(x) +// { +// for { } +// x +// { +// let _1 := 0 +// x := mload(_1) +// mstore(_1, _1) +// } +// { } +// } +// let _4 := 1337 +// let _5 := 0 +// mstore(_5, _4) +// foo(42) +// sstore(_5, mload(_5)) +// }