Only warn for shift instructions if not using constantinople

This commit is contained in:
Alex Beregszaszi 2018-02-28 08:43:18 +01:00 committed by chriseth
parent 7f8e573339
commit 5a54cd5c70
3 changed files with 13 additions and 12 deletions

View File

@ -561,19 +561,19 @@ void AsmAnalyzer::warnOnInstructions(solidity::Instruction _instr, SourceLocatio
m_evmVersion.name() + m_evmVersion.name() +
"\", where it will be interpreted as an invalid instruction." "\", where it will be interpreted as an invalid instruction."
); );
else if ((
static set<solidity::Instruction> experimentalInstructions{ _instr == solidity::Instruction::SHL ||
solidity::Instruction::SHL, _instr == solidity::Instruction::SHR ||
solidity::Instruction::SHR, _instr == solidity::Instruction::SAR
solidity::Instruction::SAR ) && !m_evmVersion.hasBitwiseShifting())
};
if (experimentalInstructions.count(_instr))
m_errorReporter.warning( m_errorReporter.warning(
_location, _location,
"The \"" + "The \"" +
boost::to_lower_copy(instructionInfo(_instr).name) boost::to_lower_copy(instructionInfo(_instr).name)
+ "\" instruction is only available after " + + "\" instruction is only available for Constantinople-compatible VMs. " +
"the Constantinople hard fork. Before that it acts as an invalid instruction." "You are currently compiling for \"" +
m_evmVersion.name() +
"\", where it will be interpreted as an invalid instruction."
); );
if (_instr == solidity::Instruction::JUMP || _instr == solidity::Instruction::JUMPI || _instr == solidity::Instruction::JUMPDEST) if (_instr == solidity::Instruction::JUMP || _instr == solidity::Instruction::JUMPI || _instr == solidity::Instruction::JUMPDEST)

View File

@ -74,6 +74,7 @@ public:
/// Has the RETURNDATACOPY and RETURNDATASIZE opcodes. /// Has the RETURNDATACOPY and RETURNDATASIZE opcodes.
bool supportsReturndata() const { return *this >= byzantium(); } bool supportsReturndata() const { return *this >= byzantium(); }
bool hasStaticCall() const { return *this >= byzantium(); } bool hasStaticCall() const { return *this >= byzantium(); }
bool hasBitwiseShifting() const { return *this >= constantinople(); }
/// Whether we have to retain the costs for the call opcode itself (false), /// Whether we have to retain the costs for the call opcode itself (false),
/// or whether we can just forward easily all remaining gas (true). /// or whether we can just forward easily all remaining gas (true).

View File

@ -783,9 +783,9 @@ BOOST_AUTO_TEST_CASE(shift)
BOOST_AUTO_TEST_CASE(shift_constantinople_warning) BOOST_AUTO_TEST_CASE(shift_constantinople_warning)
{ {
CHECK_PARSE_WARNING("{ pop(shl(10, 32)) }", Warning, "The \"shl\" instruction is only available after the Constantinople hard fork"); CHECK_PARSE_WARNING("{ pop(shl(10, 32)) }", Warning, "The \"shl\" instruction is only available for Constantinople-compatible VMs.");
CHECK_PARSE_WARNING("{ pop(shr(10, 32)) }", Warning, "The \"shr\" instruction is only available after the Constantinople hard fork"); CHECK_PARSE_WARNING("{ pop(shr(10, 32)) }", Warning, "The \"shr\" instruction is only available for Constantinople-compatible VMs.");
CHECK_PARSE_WARNING("{ pop(sar(10, 32)) }", Warning, "The \"sar\" instruction is only available after the Constantinople hard fork"); CHECK_PARSE_WARNING("{ pop(sar(10, 32)) }", Warning, "The \"sar\" instruction is only available for Constantinople-compatible VMs.");
} }
BOOST_AUTO_TEST_CASE(jump_warning) BOOST_AUTO_TEST_CASE(jump_warning)