Merge pull request #5935 from ethereum/const-opt-test

Add optimiser test for triggering CopyMethod in ConstantOpimiser
This commit is contained in:
Alex Beregszaszi 2019-02-05 19:21:05 +00:00 committed by GitHub
commit d833024d7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -630,6 +630,43 @@ BOOST_AUTO_TEST_CASE(optimise_multi_stores)
BOOST_CHECK_EQUAL(numInstructions(m_optimizedBytecode, Instruction::SSTORE), 8);
}
BOOST_AUTO_TEST_CASE(optimise_constant_to_codecopy)
{
char const* sourceCode = R"(
contract C {
// We use the state variable so that the functions won't be deemed identical
// and be optimised out to the same implementation.
uint a;
function f() public returns (uint) {
a = 1;
// This cannot be represented well with the `CalculateMethod`,
// hence the decision will be between `LiteralMethod` and `CopyMethod`.
return 0x1234123412431234123412412342112341234124312341234124;
}
function g() public returns (uint) {
a = 2;
return 0x1234123412431234123412412342112341234124312341234124;
}
function h() public returns (uint) {
a = 3;
return 0x1234123412431234123412412342112341234124312341234124;
}
function i() public returns (uint) {
a = 4;
return 0x1234123412431234123412412342112341234124312341234124;
}
}
)";
compileBothVersions(sourceCode, 0, "C", 50);
compareVersions("f()");
compareVersions("g()");
compareVersions("h()");
compareVersions("i()");
// This is counting in the deployed code.
BOOST_CHECK_EQUAL(numInstructions(m_nonOptimizedBytecode, Instruction::CODECOPY), 0);
BOOST_CHECK_EQUAL(numInstructions(m_optimizedBytecode, Instruction::CODECOPY), 4);
}
BOOST_AUTO_TEST_SUITE_END()
}