Fix assertion concerning jumps in strict assembly.

This commit is contained in:
chriseth 2019-02-13 14:50:00 +01:00
parent 10888b21d8
commit 3a3ed1c6b5
5 changed files with 24 additions and 12 deletions

View File

@ -638,6 +638,7 @@ void AsmAnalyzer::warnOnInstructions(solidity::Instruction _instr, SourceLocatio
solAssert(m_evmVersion.supportsReturndata() == m_evmVersion.hasStaticCall(), ""); solAssert(m_evmVersion.supportsReturndata() == m_evmVersion.hasStaticCall(), "");
// Similarly we assume bitwise shifting and create2 go together. // Similarly we assume bitwise shifting and create2 go together.
solAssert(m_evmVersion.hasBitwiseShifting() == m_evmVersion.hasCreate2(), ""); solAssert(m_evmVersion.hasBitwiseShifting() == m_evmVersion.hasCreate2(), "");
solAssert(m_dialect->flavour != AsmFlavour::Yul, "");
if (_instr == solidity::Instruction::EXTCODEHASH) if (_instr == solidity::Instruction::EXTCODEHASH)
m_errorReporter.warning( m_errorReporter.warning(
@ -678,19 +679,24 @@ 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 (_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)
{ {
if (m_dialect->flavour != AsmFlavour::Loose) if (m_dialect->flavour == AsmFlavour::Loose)
solAssert(m_errorTypeForLoose && *m_errorTypeForLoose != Error::Type::Warning, ""); m_errorReporter.error(
m_errorTypeForLoose ? *m_errorTypeForLoose : Error::Type::Warning,
m_errorReporter.error( _location,
m_errorTypeForLoose ? *m_errorTypeForLoose : Error::Type::Warning, "Jump instructions and labels are low-level EVM features that can lead to "
_location, "incorrect stack access. Because of that they are discouraged. "
"Jump instructions and labels are low-level EVM features that can lead to " "Please consider using \"switch\", \"if\" or \"for\" statements instead."
"incorrect stack access. Because of that they are discouraged. " );
"Please consider using \"switch\", \"if\" or \"for\" statements instead." else
); m_errorReporter.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."
);
} }
} }

View File

@ -0,0 +1 @@
--strict-assembly

View File

@ -0,0 +1,3 @@
strict_asm_jump/input.sol:1:3: Error: 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.
{ jump(1) }
^-----^

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1 @@
{ jump(1) }