diff --git a/libyul/AsmAnalysis.cpp b/libyul/AsmAnalysis.cpp index c38c0ba8e..00fd00ba4 100644 --- a/libyul/AsmAnalysis.cpp +++ b/libyul/AsmAnalysis.cpp @@ -664,7 +664,22 @@ bool AsmAnalyzer::validateInstructions(std::string const& _instructionIdentifier { auto const builtin = EVMDialect::strictAssemblyForEVM(EVMVersion{}).builtin(YulString(_instructionIdentifier)); if (builtin && builtin->instruction.has_value()) + { + if (_instructionIdentifier == "prevrandao" && !m_evmVersion.hasPrevRandao()) + m_errorReporter.warning( + 5761_error, + _location, + "\"prevrandao\" is not supported by the VM version and will be treated like \"difficulty\"." + ); + else if (_instructionIdentifier == "difficulty" && m_evmVersion.hasPrevRandao()) + m_errorReporter.warning( + 3242_error, + _location, + "\"difficulty\" was renamed and supplanted by \"prevrandao\" in the VM version paris." + ); + return validateInstructions(builtin->instruction.value(), _location); + } else return false; } @@ -684,6 +699,8 @@ bool AsmAnalyzer::validateInstructions(evmasm::Instruction _instr, SourceLocatio _instr != evmasm::Instruction::JUMPDEST, ""); + bool returnValue = true; + auto errorForVM = [&](ErrorId _errorId, string const& vmKindMessage) { m_errorReporter.typeError( _errorId, @@ -695,6 +712,7 @@ bool AsmAnalyzer::validateInstructions(evmasm::Instruction _instr, SourceLocatio fmt::arg("version", m_evmVersion.name()) ) ); + returnValue = false; }; if (_instr == evmasm::Instruction::RETURNDATACOPY && !m_evmVersion.supportsReturndata()) @@ -727,10 +745,8 @@ bool AsmAnalyzer::validateInstructions(evmasm::Instruction _instr, SourceLocatio "PC instruction is a low-level EVM feature. " "Because of that PC is disallowed in strict assembly." ); - else - return false; - return true; + return returnValue; } bool AsmAnalyzer::validateInstructions(FunctionCall const& _functionCall) diff --git a/libyul/backends/evm/EVMDialect.cpp b/libyul/backends/evm/EVMDialect.cpp index 1057b530d..2927b57d1 100644 --- a/libyul/backends/evm/EVMDialect.cpp +++ b/libyul/backends/evm/EVMDialect.cpp @@ -146,7 +146,7 @@ set createReservedIdentifiers(langutil::EVMVersion _evmVersion) map createBuiltins(langutil::EVMVersion _evmVersion, bool _objectAccess) { - auto hasOpCode = [&](evmasm::Instruction _instr, string const& _instrName) -> bool + /*auto hasOpCode = [&](evmasm::Instruction _instr, string const& _instrName) -> bool { if ( _instr == evmasm::Instruction::PREVRANDAO && @@ -155,7 +155,7 @@ map createBuiltins(langutil::EVMVersion _evmVe return _evmVersion.hasPrevRandao(); return _evmVersion.hasOpcode(_instr); - }; + };*/ map builtins; for (auto const& instr: evmasm::c_instructions) @@ -170,7 +170,7 @@ map createBuiltins(langutil::EVMVersion _evmVe opcode != evmasm::Instruction::JUMP && opcode != evmasm::Instruction::JUMPI && opcode != evmasm::Instruction::JUMPDEST && - hasOpCode(opcode, name) + _evmVersion.hasOpcode(opcode) ) builtins.emplace(createEVMFunction(name, opcode)); } diff --git a/test/libsolidity/syntaxTests/inlineAssembly/difficulty_warn_paris.sol b/test/libsolidity/syntaxTests/inlineAssembly/difficulty_warn_paris.sol index e59711394..3777868ec 100644 --- a/test/libsolidity/syntaxTests/inlineAssembly/difficulty_warn_paris.sol +++ b/test/libsolidity/syntaxTests/inlineAssembly/difficulty_warn_paris.sol @@ -4,4 +4,4 @@ function f() view returns (uint) { // ==== // EVMVersion: >=paris // ---- -// Warning 8417: (43-59): "difficulty" was renamed and supplanted by "prevrandao" in the VM version paris. +// Warning 8417: (46-62): "difficulty" was renamed and supplanted by "prevrandao" in the VM version paris. diff --git a/test/libsolidity/syntaxTests/inlineAssembly/prevrandao_warn_pre_paris.sol b/test/libsolidity/syntaxTests/inlineAssembly/prevrandao_warn_pre_paris.sol index 9779adc37..515e02ed8 100644 --- a/test/libsolidity/syntaxTests/inlineAssembly/prevrandao_warn_pre_paris.sol +++ b/test/libsolidity/syntaxTests/inlineAssembly/prevrandao_warn_pre_paris.sol @@ -4,4 +4,4 @@ function f() view returns (uint) { // ==== // EVMVersion: =london +// EVMVersion: >=paris // ---- // Warning 5740: (89-1716): Unreachable code. // Warning 5740: (1729-1741): Unreachable code. diff --git a/test/libsolidity/syntaxTests/viewPureChecker/inline_assembly_instructions_allowed_london.sol b/test/libsolidity/syntaxTests/viewPureChecker/inline_assembly_instructions_allowed_london.sol new file mode 100644 index 000000000..cff08db9a --- /dev/null +++ b/test/libsolidity/syntaxTests/viewPureChecker/inline_assembly_instructions_allowed_london.sol @@ -0,0 +1,15 @@ +contract C { + function f() public { + assembly { + pop(difficulty()) + } + } +} +// ==== +// EVMVersion: =london +// ---- +// Warning 5740: (89-1716): Unreachable code. +// Warning 5740: (1729-1741): Unreachable code. +// Warning 5740: (1754-1769): Unreachable code. +// Warning 5740: (1782-1791): Unreachable code. +// Warning 5740: (1804-2215): Unreachable code. diff --git a/test/libsolidity/syntaxTests/viewPureChecker/inline_assembly_instructions_allowed_view_london.sol b/test/libsolidity/syntaxTests/viewPureChecker/inline_assembly_instructions_allowed_view_london.sol index 39a43ea62..e8de67c3e 100644 --- a/test/libsolidity/syntaxTests/viewPureChecker/inline_assembly_instructions_allowed_view_london.sol +++ b/test/libsolidity/syntaxTests/viewPureChecker/inline_assembly_instructions_allowed_view_london.sol @@ -9,7 +9,3 @@ contract C { // ==== // EVMVersion: =london // ---- -// Warning 5740: (94-1733): Unreachable code. -// Warning 5740: (1746-1758): Unreachable code. -// Warning 5740: (1801-1810): Unreachable code. -// Warning 5740: (1978-2244): Unreachable code. diff --git a/test/libsolidity/syntaxTests/viewPureChecker/inline_assembly_instructions_disallowed_pure_london.sol b/test/libsolidity/syntaxTests/viewPureChecker/inline_assembly_instructions_disallowed_pure_london.sol index 114b9f313..f6bedfc7d 100644 --- a/test/libsolidity/syntaxTests/viewPureChecker/inline_assembly_instructions_disallowed_pure_london.sol +++ b/test/libsolidity/syntaxTests/viewPureChecker/inline_assembly_instructions_disallowed_pure_london.sol @@ -9,37 +9,4 @@ contract C { // ==== // EVMVersion: =london // ---- -// Warning 5740: (672-1083): Unreachable code. -// TypeError 2527: (79-87): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view". -// TypeError 8961: (101-113): Function cannot be declared as pure because this expression (potentially) modifies the state. -// TypeError 2527: (130-135): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view". -// TypeError 2527: (153-162): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view". -// TypeError 2527: (180-190): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view". -// TypeError 2527: (208-221): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view". -// TypeError 2527: (239-247): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view". -// TypeError 2527: (265-276): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view". -// TypeError 2527: (294-308): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view". -// TypeError 2527: (322-345): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view". -// TypeError 2527: (362-376): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view". -// TypeError 8961: (394-409): Function cannot be declared as pure because this expression (potentially) modifies the state. -// TypeError 8961: (427-446): Function cannot be declared as pure because this expression (potentially) modifies the state. -// TypeError 8961: (464-489): Function cannot be declared as pure because this expression (potentially) modifies the state. -// TypeError 8961: (507-536): Function cannot be declared as pure because this expression (potentially) modifies the state. -// TypeError 8961: (554-584): Function cannot be declared as pure because this expression (potentially) modifies the state. -// TypeError 2527: (602-630): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view". -// TypeError 8961: (644-659): Function cannot be declared as pure because this expression (potentially) modifies the state. -// TypeError 8961: (672-682): Function cannot be declared as pure because this expression (potentially) modifies the state. -// TypeError 8961: (695-708): Function cannot be declared as pure because this expression (potentially) modifies the state. -// TypeError 8961: (721-737): Function cannot be declared as pure because this expression (potentially) modifies the state. -// TypeError 8961: (750-769): Function cannot be declared as pure because this expression (potentially) modifies the state. -// TypeError 8961: (782-804): Function cannot be declared as pure because this expression (potentially) modifies the state. -// TypeError 2527: (821-830): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view". -// TypeError 2527: (848-857): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view". -// TypeError 2527: (875-883): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view". -// TypeError 2527: (901-911): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view". -// TypeError 2527: (929-941): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view". -// TypeError 2527: (959-969): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view". -// TypeError 2527: (987-998): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view". -// TypeError 2527: (1016-1024): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view". -// TypeError 2527: (1042-1054): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view". -// TypeError 2527: (1072-1082): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view". +// TypeError 2527: (111-123): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".