aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2017-12-07 19:21:52 +0800
committerGitHub <noreply@github.com>2017-12-07 19:21:52 +0800
commit316e4089b3c2317abdf1c5b43e214d1f69e16160 (patch)
tree637d4e153c17c88d0d38a3163f8eefff2ad51039
parent1343770dfe2f2231d1180dc41ff42164172bbeec (diff)
parentd57afb20fa32be3d5575b8c5dcd98f39ce4e90d0 (diff)
downloaddexon-solidity-316e4089b3c2317abdf1c5b43e214d1f69e16160.tar.gz
dexon-solidity-316e4089b3c2317abdf1c5b43e214d1f69e16160.tar.zst
dexon-solidity-316e4089b3c2317abdf1c5b43e214d1f69e16160.zip
Merge pull request #3283 from ethereum/jump-warning
Improve the jump warning
-rw-r--r--Changelog.md1
-rw-r--r--libsolidity/inlineasm/AsmAnalysis.cpp7
-rw-r--r--test/libsolidity/InlineAssembly.cpp5
3 files changed, 8 insertions, 5 deletions
diff --git a/Changelog.md b/Changelog.md
index fd256af8..248165bb 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -1,6 +1,7 @@
### 0.4.20 (unreleased)
Features:
+ * Inline Assembly: Issue warning for using jump labels (already existed for jump instructions).
Bugfixes:
diff --git a/libsolidity/inlineasm/AsmAnalysis.cpp b/libsolidity/inlineasm/AsmAnalysis.cpp
index 5c03342d..049af65f 100644
--- a/libsolidity/inlineasm/AsmAnalysis.cpp
+++ b/libsolidity/inlineasm/AsmAnalysis.cpp
@@ -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."
);
}
diff --git a/test/libsolidity/InlineAssembly.cpp b/test/libsolidity/InlineAssembly.cpp
index e9fb8431..82bafd49 100644
--- a/test/libsolidity/InlineAssembly.cpp
+++ b/test/libsolidity/InlineAssembly.cpp
@@ -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()