diff --git a/libyul/AsmAnalysis.cpp b/libyul/AsmAnalysis.cpp index 62beb3d3f..044b0780b 100644 --- a/libyul/AsmAnalysis.cpp +++ b/libyul/AsmAnalysis.cpp @@ -638,6 +638,7 @@ void AsmAnalyzer::warnOnInstructions(solidity::Instruction _instr, SourceLocatio solAssert(m_evmVersion.supportsReturndata() == m_evmVersion.hasStaticCall(), ""); // Similarly we assume bitwise shifting and create2 go together. solAssert(m_evmVersion.hasBitwiseShifting() == m_evmVersion.hasCreate2(), ""); + solAssert(m_dialect->flavour != AsmFlavour::Yul, ""); if (_instr == solidity::Instruction::EXTCODEHASH) m_errorReporter.warning( @@ -678,19 +679,24 @@ void AsmAnalyzer::warnOnInstructions(solidity::Instruction _instr, SourceLocatio m_evmVersion.name() + "\", where it will be interpreted as an invalid instruction." ); - - if (_instr == solidity::Instruction::JUMP || _instr == solidity::Instruction::JUMPI || _instr == solidity::Instruction::JUMPDEST) + else if (_instr == solidity::Instruction::JUMP || _instr == solidity::Instruction::JUMPI || _instr == solidity::Instruction::JUMPDEST) { - if (m_dialect->flavour != AsmFlavour::Loose) - solAssert(m_errorTypeForLoose && *m_errorTypeForLoose != Error::Type::Warning, ""); - - m_errorReporter.error( - m_errorTypeForLoose ? *m_errorTypeForLoose : Error::Type::Warning, - _location, - "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\", \"if\" or \"for\" statements instead." - ); + if (m_dialect->flavour == AsmFlavour::Loose) + m_errorReporter.error( + m_errorTypeForLoose ? *m_errorTypeForLoose : Error::Type::Warning, + _location, + "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\", \"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." + ); } } diff --git a/test/cmdlineTests/strict_asm_jump/args b/test/cmdlineTests/strict_asm_jump/args new file mode 100644 index 000000000..e1e6ff62e --- /dev/null +++ b/test/cmdlineTests/strict_asm_jump/args @@ -0,0 +1 @@ +--strict-assembly \ No newline at end of file diff --git a/test/cmdlineTests/strict_asm_jump/err b/test/cmdlineTests/strict_asm_jump/err new file mode 100644 index 000000000..f4033b762 --- /dev/null +++ b/test/cmdlineTests/strict_asm_jump/err @@ -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) } + ^-----^ diff --git a/test/cmdlineTests/strict_asm_jump/exit b/test/cmdlineTests/strict_asm_jump/exit new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/test/cmdlineTests/strict_asm_jump/exit @@ -0,0 +1 @@ +1 diff --git a/test/cmdlineTests/strict_asm_jump/input.sol b/test/cmdlineTests/strict_asm_jump/input.sol new file mode 100644 index 000000000..0f791eeca --- /dev/null +++ b/test/cmdlineTests/strict_asm_jump/input.sol @@ -0,0 +1 @@ +{ jump(1) } \ No newline at end of file