mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #5935 from ethereum/const-opt-test
Add optimiser test for triggering CopyMethod in ConstantOpimiser
This commit is contained in:
commit
d833024d7d
@ -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()
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user