Merge pull request #3283 from ethereum/jump-warning

Improve the jump warning
This commit is contained in:
chriseth 2017-12-07 12:21:52 +01:00 committed by GitHub
commit 316e4089b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 5 deletions

View File

@ -1,6 +1,7 @@
### 0.4.20 (unreleased)
Features:
* Inline Assembly: Issue warning for using jump labels (already existed for jump instructions).
Bugfixes:

View File

@ -56,6 +56,7 @@ bool AsmAnalyzer::operator()(Label const& _label)
{
solAssert(!m_julia, "");
m_info.stackHeightInfo[&_label] = m_stackHeight;
warnOnInstructions(solidity::Instruction::JUMPDEST, _label.location);
return true;
}
@ -523,11 +524,11 @@ void AsmAnalyzer::warnOnInstructions(solidity::Instruction _instr, SourceLocatio
"the Metropolis hard fork. Before that it acts as an invalid instruction."
);
if (_instr == solidity::Instruction::JUMP || _instr == solidity::Instruction::JUMPI)
if (_instr == solidity::Instruction::JUMP || _instr == solidity::Instruction::JUMPI || _instr == solidity::Instruction::JUMPDEST)
m_errorReporter.warning(
_location,
"Jump instructions are low-level EVM features that can lead to "
"Jump instructions and labels are low-level EVM features that can lead to "
"incorrect stack access. Because of that they are discouraged. "
"Please consider using \"switch\" or \"for\" statements instead."
"Please consider using \"switch\", \"if\" or \"for\" statements instead."
);
}

View File

@ -712,8 +712,9 @@ BOOST_AUTO_TEST_CASE(jump_warning)
{
CHECK_PARSE_WARNING("{ 1 jump }", Warning, "Jump instructions");
CHECK_PARSE_WARNING("{ 1 2 jumpi }", Warning, "Jump instructions");
CHECK_PARSE_WARNING("{ a: jump(a) }", Warning, "Jump instructions");
CHECK_PARSE_WARNING("{ a: jumpi(a, 2) }", Warning, "Jump instructions");
CHECK_PARSE_WARNING("{ jump(44) }", Warning, "Jump instructions");
CHECK_PARSE_WARNING("{ jumpi(44, 2) }", Warning, "Jump instructions");
CHECK_PARSE_WARNING("{ a: }", Warning, "Jump instructions");
}
BOOST_AUTO_TEST_SUITE_END()