Use "none" and "full" optimizer settings in the optimizer tests.

This commit is contained in:
chriseth 2019-03-12 15:14:12 +01:00
parent 2fd6661b09
commit d788a88873
5 changed files with 18 additions and 19 deletions

View File

@ -57,7 +57,7 @@ ExecutionFramework::ExecutionFramework():
ExecutionFramework::ExecutionFramework(string const& _ipcPath, langutil::EVMVersion _evmVersion):
m_rpc(RPCSession::instance(_ipcPath)),
m_evmVersion(_evmVersion),
m_optimize(dev::test::Options::get().optimize),
m_optimiserSettings(dev::test::Options::get().optimize ? solidity::OptimiserSettings::enabled() : solidity::OptimiserSettings::minimal()),
m_showMessages(dev::test::Options::get().showMessages),
m_sender(m_rpc.account(0))
{

View File

@ -25,6 +25,8 @@
#include <test/Options.h>
#include <test/RPCSession.h>
#include <libsolidity/interface/OptimiserSettings.h>
#include <liblangutil/EVMVersion.h>
#include <libdevcore/FixedHash.h>
@ -265,8 +267,7 @@ protected:
};
langutil::EVMVersion m_evmVersion;
unsigned m_optimizeRuns = 200;
bool m_optimize = false;
solidity::OptimiserSettings m_optimiserSettings = solidity::OptimiserSettings::minimal();
bool m_showMessages = false;
bool m_transactionSuccessful = true;
Address m_sender;

View File

@ -41,7 +41,7 @@ namespace test
u256 gasOpt{_gasOpt}; \
u256 gasNoOpt{_gasNoOpt}; \
u256 tolerance{_tolerance}; \
u256 gas = m_optimize ? gasOpt : gasNoOpt; \
u256 gas = m_optimiserSettings == OptimiserSettings::minimal() ? gasNoOpt : gasOpt; \
u256 diff = gas < m_gasUsed ? m_gasUsed - gas : gas - m_gasUsed; \
BOOST_CHECK_MESSAGE( \
diff <= tolerance, \

View File

@ -73,7 +73,7 @@ public:
m_compiler.addSource("", sourceCode);
m_compiler.setLibraries(_libraryAddresses);
m_compiler.setEVMVersion(m_evmVersion);
m_compiler.setOptimiserSettings(m_optimize, m_optimizeRuns);
m_compiler.setOptimiserSettings(m_optimiserSettings);
if (!m_compiler.compile())
{
langutil::SourceReferenceFormatter formatter(std::cerr);

View File

@ -54,13 +54,13 @@ public:
unsigned const _optimizeRuns = 200
)
{
bool const c_optimize = m_optimize;
unsigned const c_optimizeRuns = m_optimizeRuns;
m_optimize = _optimize;
m_optimizeRuns = _optimizeRuns;
OptimiserSettings previousSettings = std::move(m_optimiserSettings);
// This uses "none" / "full" while most other test frameworks use
// "minimal" / "enabled".
m_optimiserSettings = _optimize ? OptimiserSettings::full() : OptimiserSettings::none();
m_optimiserSettings.expectedExecutionsPerDeployment = _optimizeRuns;
bytes const& ret = compileAndRun(_sourceCode, _value, _contractName);
m_optimize = c_optimize;
m_optimizeRuns = c_optimizeRuns;
m_optimiserSettings = std::move(previousSettings);
return ret;
}
@ -685,21 +685,19 @@ BOOST_AUTO_TEST_CASE(shift_optimizer_bug)
char const* sourceCode = R"(
contract C
{
function f(uint x, uint y, uint z) public returns (uint)
function f(uint x) public returns (uint)
{
return (x << y) << z;
return (x << 1) << uint(-1);
}
function g(uint x, uint y, uint z) public returns (uint)
function g(uint x) public returns (uint)
{
return (x >> y) > z;
return (x >> 1) >> uint(-1);
}
}
)";
compileBothVersions(sourceCode);
compareVersions("f(uint256,uint256,uint256)", 7, u256(-1), 5);
compareVersions("g(uint256,uint256,uint256)", 7, u256(-1), 5);
compareVersions("f(uint256,uint256,uint256)", 7, 128, 120);
compareVersions("g(uint256,uint256,uint256)", 0x71117, 2, 2);
compareVersions("f(uint256)", 7);
compareVersions("g(uint256)", u256(-1));
}