diff options
author | Christian <c@ethdev.com> | 2014-12-12 00:35:23 +0800 |
---|---|---|
committer | Christian <c@ethdev.com> | 2014-12-12 00:48:44 +0800 |
commit | c68d1c62e0fbf0b656ced8c0aab9017370c1ed33 (patch) | |
tree | 6e6c4d8dd43c30eb51a7620364744b45f32c3370 | |
parent | 1db9bc1651c4ee2c40cb603ea33b291ac96754ce (diff) | |
download | dexon-solidity-c68d1c62e0fbf0b656ced8c0aab9017370c1ed33.tar.gz dexon-solidity-c68d1c62e0fbf0b656ced8c0aab9017370c1ed33.tar.zst dexon-solidity-c68d1c62e0fbf0b656ced8c0aab9017370c1ed33.zip |
Swap literals to the end if optimizing.
-rw-r--r-- | solidityOptimizerTest.cpp | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/solidityOptimizerTest.cpp b/solidityOptimizerTest.cpp index f8d3b552..69000a57 100644 --- a/solidityOptimizerTest.cpp +++ b/solidityOptimizerTest.cpp @@ -48,7 +48,7 @@ public: m_optimize = true; bytes optimizedBytecode = compileAndRun(_sourceCode, _value, _contractName); int sizeDiff = nonOptimizedBytecode.size() - optimizedBytecode.size(); - BOOST_CHECK_MESSAGE(sizeDiff >= _expectedSizeDecrease, "Bytecode did only shrink by " + BOOST_CHECK_MESSAGE(sizeDiff == _expectedSizeDecrease, "Bytecode did only shrink by " + boost::lexical_cast<string>(sizeDiff) + " bytes, expected: " + boost::lexical_cast<string>(_expectedSizeDecrease)); m_optimizedContract = m_contractAddress; @@ -106,7 +106,7 @@ BOOST_AUTO_TEST_CASE(invariants) return (((a + (1 - 1)) ^ 0) | 0) & (uint(0) - 1); } })"; - compileBothVersions(19, sourceCode); + compileBothVersions(28, sourceCode); compareVersions(0, u256(0x12334664)); } @@ -124,6 +124,21 @@ BOOST_AUTO_TEST_CASE(unused_expressions) compareVersions(0); } +BOOST_AUTO_TEST_CASE(constant_folding_both_sides) +{ + // if constants involving the same associative and commutative operator are applied from both + // sides, the operator should be applied only once, because the expression compiler + // (even in non-optimized mode) pushes literals as late as possible + char const* sourceCode = R"( + contract test { + function f(uint x) returns (uint y) { + return 98 ^ (7 * ((1 | (x | 1000)) * 40) ^ 102); + } + })"; + compileBothVersions(31, sourceCode); + compareVersions(0); +} + BOOST_AUTO_TEST_SUITE_END() } |