aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/inlineasm/AsmAnalysis.cpp
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2017-06-14 02:10:26 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2017-07-01 03:47:14 +0800
commitd4fecc7b11586a108578a1834b634981bc854f91 (patch)
tree579974aa17010ee8a3d5151cccff7e54c3e15f41 /libsolidity/inlineasm/AsmAnalysis.cpp
parent95f790295564997705f455e3ed18b6c51546a847 (diff)
downloaddexon-solidity-d4fecc7b11586a108578a1834b634981bc854f91.tar.gz
dexon-solidity-d4fecc7b11586a108578a1834b634981bc854f91.tar.zst
dexon-solidity-d4fecc7b11586a108578a1834b634981bc854f91.zip
Warn on JUMP/JUMPI in inline assembly
Diffstat (limited to 'libsolidity/inlineasm/AsmAnalysis.cpp')
-rw-r--r--libsolidity/inlineasm/AsmAnalysis.cpp13
1 files changed, 10 insertions, 3 deletions
diff --git a/libsolidity/inlineasm/AsmAnalysis.cpp b/libsolidity/inlineasm/AsmAnalysis.cpp
index b0d044ae..7e00ffae 100644
--- a/libsolidity/inlineasm/AsmAnalysis.cpp
+++ b/libsolidity/inlineasm/AsmAnalysis.cpp
@@ -65,7 +65,7 @@ bool AsmAnalyzer::operator()(assembly::Instruction const& _instruction)
auto const& info = instructionInfo(_instruction.instruction);
m_stackHeight += info.ret - info.args;
m_info.stackHeightInfo[&_instruction] = m_stackHeight;
- warnOnFutureInstruction(_instruction.instruction, _instruction.location);
+ warnOnInstructions(_instruction.instruction, _instruction.location);
return true;
}
@@ -150,7 +150,6 @@ bool AsmAnalyzer::operator()(FunctionalInstruction const& _instr)
if (!(*this)(_instr.instruction))
success = false;
m_info.stackHeightInfo[&_instr] = m_stackHeight;
- warnOnFutureInstruction(_instr.instruction.instruction, _instr.location);
return success;
}
@@ -470,7 +469,7 @@ void AsmAnalyzer::expectValidType(string const& type, SourceLocation const& _loc
);
}
-void AsmAnalyzer::warnOnFutureInstruction(solidity::Instruction _instr, SourceLocation const& _location)
+void AsmAnalyzer::warnOnInstructions(solidity::Instruction _instr, SourceLocation const& _location)
{
static set<solidity::Instruction> futureInstructions{
solidity::Instruction::CREATE2,
@@ -486,4 +485,12 @@ void AsmAnalyzer::warnOnFutureInstruction(solidity::Instruction _instr, SourceLo
+ "\" instruction is only available after " +
"the Metropolis hard fork. Before that it acts as an invalid instruction."
);
+
+ if (_instr == solidity::Instruction::JUMP || _instr == solidity::Instruction::JUMPI)
+ m_errorReporter.warning(
+ _location,
+ "Jump instructions 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."
+ );
}