From b1f79072dfa5e51a68ba597009c55fd8ad4ea65f Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 23 Jul 2020 13:55:17 +0200 Subject: [PATCH] Fix stack compressor wrt literal arguments. --- libyul/backends/evm/NoOutputAssembly.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/libyul/backends/evm/NoOutputAssembly.cpp b/libyul/backends/evm/NoOutputAssembly.cpp index 733795523..ced32af6a 100644 --- a/libyul/backends/evm/NoOutputAssembly.cpp +++ b/libyul/backends/evm/NoOutputAssembly.cpp @@ -163,14 +163,21 @@ NoOutputEVMDialect::NoOutputEVMDialect(EVMDialect const& _copyFrom): { for (auto& fun: m_functions) { - size_t parameters = fun.second.parameters.size(); size_t returns = fun.second.returns.size(); fun.second.generateCode = [=](FunctionCall const& _call, AbstractAssembly& _assembly, BuiltinContext&, std::function _visitExpression) { - for (auto const& arg: _call.arguments | boost::adaptors::reversed) - _visitExpression(arg); + size_t visited = 0; + for (size_t j = 0; j < _call.arguments.size(); j++) + { + size_t const i = _call.arguments.size() - j - 1; + if (!(fun.second.literalArguments && (*fun.second.literalArguments)[i])) + { + _visitExpression(_call.arguments[i]); + visited++; + } + } - for (size_t i = 0; i < parameters; i++) + for (size_t i = 0; i < visited; i++) _assembly.appendInstruction(evmasm::Instruction::POP); for (size_t i = 0; i < returns; i++)