Merge pull request #9316 from ethereum/yul-cleanup-evm

Tiny cleanups to EVMDialect in Yul
This commit is contained in:
chriseth 2020-07-06 16:14:24 +02:00 committed by GitHub
commit 375cb09341
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 13 deletions

View File

@ -558,6 +558,13 @@ bool AsmAnalyzer::validateInstructions(evmasm::Instruction _instr, SourceLocatio
// Similarly we assume bitwise shifting and create2 go together.
yulAssert(m_evmVersion.hasBitwiseShifting() == m_evmVersion.hasCreate2(), "");
// These instructions are disabled in the dialect.
yulAssert(
_instr != evmasm::Instruction::JUMP &&
_instr != evmasm::Instruction::JUMPI &&
_instr != evmasm::Instruction::JUMPDEST,
"");
auto errorForVM = [&](ErrorId _errorId, string const& vmKindMessage) {
m_errorReporter.typeError(
_errorId,
@ -602,19 +609,6 @@ bool AsmAnalyzer::validateInstructions(evmasm::Instruction _instr, SourceLocatio
);
else if (_instr == evmasm::Instruction::SELFBALANCE && !m_evmVersion.hasSelfBalance())
errorForVM(3672_error, "only available for Istanbul-compatible");
else if (
_instr == evmasm::Instruction::JUMP ||
_instr == evmasm::Instruction::JUMPI ||
_instr == evmasm::Instruction::JUMPDEST
)
m_errorReporter.error(
4316_error,
Error::Type::SyntaxError,
_location,
"Jump instructions and labels are low-level EVM features that can lead to "
"incorrect stack access. Because of that they are disallowed in strict assembly. "
"Use functions, \"switch\", \"if\" or \"for\" statements instead."
);
else
return false;

View File

@ -114,12 +114,15 @@ pair<YulString, BuiltinFunctionForEVM> createFunction(
map<YulString, BuiltinFunctionForEVM> createBuiltins(langutil::EVMVersion _evmVersion, bool _objectAccess)
{
map<YulString, BuiltinFunctionForEVM> builtins;
// NOTE: Parser::instructions() will filter JUMPDEST and PUSHnn too
for (auto const& instr: Parser::instructions())
if (
!evmasm::isDupInstruction(instr.second) &&
!evmasm::isSwapInstruction(instr.second) &&
!evmasm::isPushInstruction(instr.second) &&
instr.second != evmasm::Instruction::JUMP &&
instr.second != evmasm::Instruction::JUMPI &&
instr.second != evmasm::Instruction::JUMPDEST &&
_evmVersion.hasOpcode(instr.second)
)
builtins.emplace(createEVMFunction(instr.first, instr.second));

View File

@ -0,0 +1,9 @@
contract C {
function f() pure public {
assembly {
jumpi(2, 1)
}
}
}
// ----
// DeclarationError 4619: (75-80): Function not found.