aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/SolidityOptimizer.cpp
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2015-06-01 18:32:59 +0800
committerchriseth <c@ethdev.com>2015-06-05 23:34:26 +0800
commit4111cdf376de08ae45a2e0ca4105132fa3f8985f (patch)
tree399daa65a933d6a25de47cfc90881367646e175b /libsolidity/SolidityOptimizer.cpp
parent8ba801ec0e885ebca5babadef007f20bcdde1f0b (diff)
downloaddexon-solidity-4111cdf376de08ae45a2e0ca4105132fa3f8985f.tar.gz
dexon-solidity-4111cdf376de08ae45a2e0ca4105132fa3f8985f.tar.zst
dexon-solidity-4111cdf376de08ae45a2e0ca4105132fa3f8985f.zip
Compute constants
Diffstat (limited to 'libsolidity/SolidityOptimizer.cpp')
-rw-r--r--libsolidity/SolidityOptimizer.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/libsolidity/SolidityOptimizer.cpp b/libsolidity/SolidityOptimizer.cpp
index 827d8833..4ed081fd 100644
--- a/libsolidity/SolidityOptimizer.cpp
+++ b/libsolidity/SolidityOptimizer.cpp
@@ -1036,6 +1036,51 @@ BOOST_AUTO_TEST_CASE(block_deduplicator_loops)
BOOST_CHECK_EQUAL(pushTags.size(), 1);
}
+BOOST_AUTO_TEST_CASE(computing_constants)
+{
+ char const* sourceCode = R"(
+ contract c {
+ uint a;
+ uint b;
+ uint c;
+ function set() returns (uint a, uint b, uint c) {
+ a = 0x77abc0000000000000000000000000000000000000000000000000000000001;
+ b = 0x817416927846239487123469187231298734162934871263941234127518276;
+ g();
+ }
+ function g() {
+ b = 0x817416927846239487123469187231298734162934871263941234127518276;
+ c = 0x817416927846239487123469187231298734162934871263941234127518276;
+ }
+ function get() returns (uint ra, uint rb, uint rc) {
+ ra = a;
+ rb = b;
+ rc = c ;
+ }
+ }
+ )";
+ compileBothVersions(sourceCode);
+ compareVersions("set()");
+ compareVersions("get()");
+
+ m_optimize = true;
+ m_optimizeRuns = 1;
+ bytes optimizedBytecode = compileAndRun(sourceCode, 0, "c");
+ bytes complicatedConstant = toBigEndian(u256("0x817416927846239487123469187231298734162934871263941234127518276"));
+ unsigned occurrences = 0;
+ for (auto iter = optimizedBytecode.cbegin(); iter < optimizedBytecode.cend(); ++occurrences)
+ iter = search(iter, optimizedBytecode.cend(), complicatedConstant.cbegin(), complicatedConstant.cend()) + 1;
+ BOOST_CHECK_EQUAL(2, occurrences);
+
+ bytes constantWithZeros = toBigEndian(u256("0x77abc0000000000000000000000000000000000000000000000000000000001"));
+ BOOST_CHECK(search(
+ optimizedBytecode.cbegin(),
+ optimizedBytecode.cend(),
+ constantWithZeros.cbegin(),
+ constantWithZeros.cend()
+ ) == optimizedBytecode.cend());
+}
+
BOOST_AUTO_TEST_SUITE_END()
}