diff options
author | Alex Beregszaszi <alex@rtfs.hu> | 2018-04-03 22:58:11 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-03 22:58:11 +0800 |
commit | 0edce4b570c157927933697b30f0f94cbdf173b2 (patch) | |
tree | a7ec50f920090e529b435e878e4df8cedd1f0eb4 /test/libsolidity/SolidityEndToEndTest.cpp | |
parent | 7753249f646f239819c62ab6847438dc84b6e04b (diff) | |
parent | deadff263fbf4d5da911d7c544821cc77081a6d3 (diff) | |
download | dexon-solidity-0edce4b570c157927933697b30f0f94cbdf173b2.tar dexon-solidity-0edce4b570c157927933697b30f0f94cbdf173b2.tar.gz dexon-solidity-0edce4b570c157927933697b30f0f94cbdf173b2.tar.bz2 dexon-solidity-0edce4b570c157927933697b30f0f94cbdf173b2.tar.lz dexon-solidity-0edce4b570c157927933697b30f0f94cbdf173b2.tar.xz dexon-solidity-0edce4b570c157927933697b30f0f94cbdf173b2.tar.zst dexon-solidity-0edce4b570c157927933697b30f0f94cbdf173b2.zip |
Merge pull request #3693 from ethereum/optimizeMLOAD
Optimize across MLOAD if MSIZE is not used.
Diffstat (limited to 'test/libsolidity/SolidityEndToEndTest.cpp')
-rw-r--r-- | test/libsolidity/SolidityEndToEndTest.cpp | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index f5813aed..38d3ce4d 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -8756,6 +8756,32 @@ BOOST_AUTO_TEST_CASE(create_dynamic_array_with_zero_length) ABI_CHECK(callContractFunction("f()"), encodeArgs(u256(7))); } +BOOST_AUTO_TEST_CASE(correctly_initialize_memory_array_in_constructor) +{ + // Memory arrays are initialized using codecopy past the size of the code. + // This test checks that it also works in the constructor context. + char const* sourceCode = R"( + contract C { + bool public success; + function C() public { + // Make memory dirty. + assembly { + for { let i := 0 } lt(i, 64) { i := add(i, 1) } { + mstore(msize, not(0)) + } + } + uint16[3] memory c; + require(c[0] == 0 && c[1] == 0 && c[2] == 0); + uint16[] memory x = new uint16[](3); + require(x[0] == 0 && x[1] == 0 && x[2] == 0); + success = true; + } + } + )"; + compileAndRun(sourceCode, 0, "C"); + ABI_CHECK(callContractFunction("success()"), encodeArgs(u256(1))); +} + BOOST_AUTO_TEST_CASE(return_does_not_skip_modifier) { char const* sourceCode = R"( @@ -9119,7 +9145,7 @@ BOOST_AUTO_TEST_CASE(calling_uninitialized_function_in_detail) int mutex; function t() returns (uint) { if (mutex > 0) - return 7; + { assembly { mstore(0, 7) return(0, 0x20) } } mutex = 1; // Avoid re-executing this function if we jump somewhere. x(); @@ -9132,6 +9158,27 @@ BOOST_AUTO_TEST_CASE(calling_uninitialized_function_in_detail) ABI_CHECK(callContractFunction("t()"), encodeArgs()); } +BOOST_AUTO_TEST_CASE(calling_uninitialized_function_through_array) +{ + char const* sourceCode = R"( + contract C { + int mutex; + function t() returns (uint) { + if (mutex > 0) + { assembly { mstore(0, 7) return(0, 0x20) } } + mutex = 1; + // Avoid re-executing this function if we jump somewhere. + function() internal returns (uint)[200] x; + x[0](); + return 2; + } + } + )"; + + compileAndRun(sourceCode, 0, "C"); + ABI_CHECK(callContractFunction("t()"), encodeArgs()); +} + BOOST_AUTO_TEST_CASE(pass_function_types_internally) { char const* sourceCode = R"( |