From 33e7b24df05f53ba964d9dc4f315e989400f20eb Mon Sep 17 00:00:00 2001 From: Djordje Mijovic Date: Tue, 2 Jun 2020 15:34:28 +0200 Subject: [PATCH] Adding fixes for signedness conversion warnings in libyul MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Kamil ƚliwak --- libyul/AsmAnalysis.cpp | 4 +- libyul/Utilities.cpp | 2 +- libyul/YulString.h | 4 +- libyul/backends/evm/AsmCodeGen.cpp | 6 +- libyul/backends/evm/EVMAssembly.cpp | 6 +- libyul/backends/evm/EVMCodeTransform.cpp | 69 ++++++++++++---------- libyul/backends/evm/EVMCodeTransform.h | 4 +- libyul/backends/evm/EVMDialect.cpp | 4 +- libyul/backends/evm/EVMMetrics.cpp | 6 +- libyul/backends/wasm/BinaryTransform.cpp | 4 +- libyul/backends/wasm/WordSizeTransform.cpp | 22 +++---- libyul/optimiser/DeadCodeEliminator.cpp | 5 +- libyul/optimiser/ExpressionJoiner.cpp | 2 +- libyul/optimiser/Semantics.cpp | 2 +- libyul/optimiser/StackCompressor.cpp | 6 +- 15 files changed, 78 insertions(+), 68 deletions(-) diff --git a/libyul/AsmAnalysis.cpp b/libyul/AsmAnalysis.cpp index eee3beacb..07db82095 100644 --- a/libyul/AsmAnalysis.cpp +++ b/libyul/AsmAnalysis.cpp @@ -137,7 +137,7 @@ vector AsmAnalyzer::operator()(Identifier const& _identifier) { bool insideFunction = m_currentScope->insideFunction(); size_t stackSize = m_resolver(_identifier, yul::IdentifierContext::RValue, insideFunction); - if (stackSize != size_t(-1)) + if (stackSize != numeric_limits::max()) { found = true; yulAssert(stackSize == 1, "Invalid stack size of external reference."); @@ -479,7 +479,7 @@ void AsmAnalyzer::checkAssignment(Identifier const& _variable, YulString _valueT { bool insideFunction = m_currentScope->insideFunction(); size_t variableSize = m_resolver(_variable, yul::IdentifierContext::LValue, insideFunction); - if (variableSize != size_t(-1)) + if (variableSize != numeric_limits::max()) { found = true; variableType = &m_dialect.defaultType; diff --git a/libyul/Utilities.cpp b/libyul/Utilities.cpp index a797258eb..59e0adce3 100644 --- a/libyul/Utilities.cpp +++ b/libyul/Utilities.cpp @@ -45,7 +45,7 @@ string solidity::yul::reindent(string const& _code) auto const static countBraces = [](string const& _s) noexcept -> int { auto const i = _s.find("//"); - auto const e = i == _s.npos ? end(_s) : next(begin(_s), i); + auto const e = i == _s.npos ? end(_s) : next(begin(_s), static_cast(i)); auto const opening = count_if(begin(_s), e, [](auto ch) { return ch == '{' || ch == '('; }); auto const closing = count_if(begin(_s), e, [](auto ch) { return ch == '}' || ch == ')'; }); return opening - closing; diff --git a/libyul/YulString.h b/libyul/YulString.h index 9166cff3d..0abe1f38d 100644 --- a/libyul/YulString.h +++ b/libyul/YulString.h @@ -71,10 +71,10 @@ public: { // FNV hash - can be replaced by a better one, e.g. xxhash64 std::uint64_t hash = emptyHash(); - for (auto c: v) + for (char c: v) { hash *= 1099511628211u; - hash ^= c; + hash ^= static_cast(c); } return hash; diff --git a/libyul/backends/evm/AsmCodeGen.cpp b/libyul/backends/evm/AsmCodeGen.cpp index eefff5b18..6775214e8 100644 --- a/libyul/backends/evm/AsmCodeGen.cpp +++ b/libyul/backends/evm/AsmCodeGen.cpp @@ -143,14 +143,14 @@ pair, AbstractAssembly::SubID> EthAssemblyAdapter:: { shared_ptr assembly{make_shared()}; auto sub = m_assembly.newSub(assembly); - return {make_shared(*assembly), size_t(sub.data())}; + return {make_shared(*assembly), static_cast(sub.data())}; } void EthAssemblyAdapter::appendDataOffset(AbstractAssembly::SubID _sub) { auto it = m_dataHashBySubId.find(_sub); if (it == m_dataHashBySubId.end()) - m_assembly.pushSubroutineOffset(size_t(_sub)); + m_assembly.pushSubroutineOffset(_sub); else m_assembly << evmasm::AssemblyItem(evmasm::PushData, it->second); } @@ -159,7 +159,7 @@ void EthAssemblyAdapter::appendDataSize(AbstractAssembly::SubID _sub) { auto it = m_dataHashBySubId.find(_sub); if (it == m_dataHashBySubId.end()) - m_assembly.pushSubroutineSize(size_t(_sub)); + m_assembly.pushSubroutineSize(static_cast(_sub)); else m_assembly << u256(m_assembly.data(h256(it->second)).size()); } diff --git a/libyul/backends/evm/EVMAssembly.cpp b/libyul/backends/evm/EVMAssembly.cpp index 47f7509a3..c13a16083 100644 --- a/libyul/backends/evm/EVMAssembly.cpp +++ b/libyul/backends/evm/EVMAssembly.cpp @@ -74,7 +74,7 @@ void EVMAssembly::appendLabelReference(LabelID _labelId) EVMAssembly::LabelID EVMAssembly::newLabelId() { - m_labelPositions[m_nextLabelId] = size_t(-1); + m_labelPositions[m_nextLabelId] = numeric_limits::max(); return m_nextLabelId++; } @@ -165,7 +165,7 @@ evmasm::LinkerObject EVMAssembly::finalize() size_t referencePos = ref.first; yulAssert(m_labelPositions.count(ref.second), ""); size_t labelPos = m_labelPositions.at(ref.second); - yulAssert(labelPos != size_t(-1), "Undefined but allocated label used."); + yulAssert(labelPos != numeric_limits::max(), "Undefined but allocated label used."); updateReference(referencePos, labelReferenceSize, u256(labelPos)); } @@ -177,7 +177,7 @@ evmasm::LinkerObject EVMAssembly::finalize() void EVMAssembly::setLabelToCurrentPosition(LabelID _labelId) { yulAssert(m_labelPositions.count(_labelId), "Label not found."); - yulAssert(m_labelPositions[_labelId] == size_t(-1), "Label already set."); + yulAssert(m_labelPositions[_labelId] == numeric_limits::max(), "Label already set."); m_labelPositions[_labelId] = m_bytecode.size(); } diff --git a/libyul/backends/evm/EVMCodeTransform.cpp b/libyul/backends/evm/EVMCodeTransform.cpp index a4e19998f..f57fd35f3 100644 --- a/libyul/backends/evm/EVMCodeTransform.cpp +++ b/libyul/backends/evm/EVMCodeTransform.cpp @@ -175,28 +175,29 @@ void CodeTransform::operator()(VariableDeclaration const& _varDecl) { yulAssert(m_scope, ""); - int const numVariables = _varDecl.variables.size(); - int heightAtStart = m_assembly.stackHeight(); + size_t const numVariables = _varDecl.variables.size(); + auto heightAtStart = static_cast(m_assembly.stackHeight()); if (_varDecl.value) { std::visit(*this, *_varDecl.value); - expectDeposit(numVariables, heightAtStart); + expectDeposit(static_cast(numVariables), static_cast(heightAtStart)); } else { m_assembly.setSourceLocation(_varDecl.location); - int variablesLeft = numVariables; + size_t variablesLeft = numVariables; while (variablesLeft--) m_assembly.appendConstant(u256(0)); } m_assembly.setSourceLocation(_varDecl.location); bool atTopOfStack = true; - for (int varIndex = numVariables - 1; varIndex >= 0; --varIndex) + for (size_t varIndex = 0; varIndex < numVariables; ++varIndex) { - YulString varName = _varDecl.variables[varIndex].name; + size_t varIndexReverse = numVariables - 1 - varIndex; + YulString varName = _varDecl.variables[varIndexReverse].name; auto& var = std::get(m_scope->identifiers.at(varName)); - m_context->variableStackHeights[&var] = heightAtStart + varIndex; + m_context->variableStackHeights[&var] = heightAtStart + varIndexReverse; if (!m_allowStackOpt) continue; @@ -214,10 +215,10 @@ void CodeTransform::operator()(VariableDeclaration const& _varDecl) atTopOfStack = false; else { - int slot = *m_unusedStackSlots.begin(); + auto slot = static_cast(*m_unusedStackSlots.begin()); m_unusedStackSlots.erase(m_unusedStackSlots.begin()); m_context->variableStackHeights[&var] = slot; - if (int heightDiff = variableHeightDiff(var, varName, true)) + if (size_t heightDiff = variableHeightDiff(var, varName, true)) m_assembly.appendInstruction(evmasm::swapInstruction(heightDiff - 1)); m_assembly.appendInstruction(evmasm::Instruction::POP); } @@ -240,7 +241,7 @@ void CodeTransform::operator()(Assignment const& _assignment) { int height = m_assembly.stackHeight(); std::visit(*this, *_assignment.value); - expectDeposit(_assignment.variableNames.size(), height); + expectDeposit(static_cast(_assignment.variableNames.size()), height); m_assembly.setSourceLocation(_assignment.location); generateMultiAssignment(_assignment.variableNames); @@ -263,7 +264,7 @@ void CodeTransform::operator()(FunctionCall const& _call) else { m_assembly.setSourceLocation(_call.location); - EVMAssembly::LabelID returnLabel(-1); // only used for evm 1.0 + EVMAssembly::LabelID returnLabel(numeric_limits::max()); // only used for evm 1.0 if (!m_evm15) { returnLabel = m_assembly.newLabelId(); @@ -281,10 +282,17 @@ void CodeTransform::operator()(FunctionCall const& _call) visitExpression(arg); m_assembly.setSourceLocation(_call.location); if (m_evm15) - m_assembly.appendJumpsub(functionEntryID(_call.functionName.name, *function), function->arguments.size(), function->returns.size()); + m_assembly.appendJumpsub( + functionEntryID(_call.functionName.name, *function), + static_cast(function->arguments.size()), + static_cast(function->returns.size()) + ); else { - m_assembly.appendJumpTo(functionEntryID(_call.functionName.name, *function), function->returns.size() - function->arguments.size() - 1); + m_assembly.appendJumpTo( + functionEntryID(_call.functionName.name, *function), + static_cast(function->returns.size() - function->arguments.size()) - 1 + ); m_assembly.appendLabel(returnLabel); } } @@ -300,7 +308,7 @@ void CodeTransform::operator()(Identifier const& _identifier) { // TODO: opportunity for optimization: Do not DUP if this is the last reference // to the top most element of the stack - if (int heightDiff = variableHeightDiff(_var, _identifier.name, false)) + if (size_t heightDiff = variableHeightDiff(_var, _identifier.name, false)) m_assembly.appendInstruction(evmasm::dupInstruction(heightDiff)); else // Store something to balance the stack @@ -407,7 +415,7 @@ void CodeTransform::operator()(FunctionDefinition const& _function) int const stackHeightBefore = m_assembly.stackHeight(); if (m_evm15) - m_assembly.appendBeginsub(functionEntryID(_function.name, function), _function.parameters.size()); + m_assembly.appendBeginsub(functionEntryID(_function.name, function), static_cast(_function.parameters.size())); else m_assembly.appendLabel(functionEntryID(_function.name, function)); @@ -465,15 +473,15 @@ void CodeTransform::operator()(FunctionDefinition const& _function) // modified parallel to the actual stack. vector stackLayout; if (!m_evm15) - stackLayout.push_back(_function.returnVariables.size()); // Move return label to the top + stackLayout.push_back(static_cast(_function.returnVariables.size())); // Move return label to the top stackLayout += vector(_function.parameters.size(), -1); // discard all arguments for (size_t i = 0; i < _function.returnVariables.size(); ++i) - stackLayout.push_back(i); // Move return values down, but keep order. + stackLayout.push_back(static_cast(i)); // Move return values down, but keep order. if (stackLayout.size() > 17) { - StackTooDeepError error(_function.name, YulString{}, stackLayout.size() - 17); + StackTooDeepError error(_function.name, YulString{}, static_cast(stackLayout.size()) - 17); error << errinfo_comment( "The function " + _function.name.str() + @@ -481,11 +489,11 @@ void CodeTransform::operator()(FunctionDefinition const& _function) to_string(stackLayout.size() - 17) + " parameters or return variables too many to fit the stack size." ); - stackError(std::move(error), m_assembly.stackHeight() - _function.parameters.size()); + stackError(std::move(error), m_assembly.stackHeight() - static_cast(_function.parameters.size())); } else { - while (!stackLayout.empty() && stackLayout.back() != int(stackLayout.size() - 1)) + while (!stackLayout.empty() && stackLayout.back() != static_cast(stackLayout.size() - 1)) if (stackLayout.back() < 0) { m_assembly.appendInstruction(evmasm::Instruction::POP); @@ -493,17 +501,17 @@ void CodeTransform::operator()(FunctionDefinition const& _function) } else { - m_assembly.appendInstruction(evmasm::swapInstruction(stackLayout.size() - stackLayout.back() - 1)); - swap(stackLayout[stackLayout.back()], stackLayout.back()); + m_assembly.appendInstruction(evmasm::swapInstruction(stackLayout.size() - static_cast(stackLayout.back()) - 1)); + swap(stackLayout[static_cast(stackLayout.back())], stackLayout.back()); } - for (int i = 0; size_t(i) < stackLayout.size(); ++i) - yulAssert(i == stackLayout[i], "Error reshuffling stack."); + for (size_t i = 0; i < stackLayout.size(); ++i) + yulAssert(i == static_cast(stackLayout[i]), "Error reshuffling stack."); } } if (m_evm15) - m_assembly.appendReturnsub(_function.returnVariables.size(), stackHeightBefore); + m_assembly.appendReturnsub(static_cast(_function.returnVariables.size()), stackHeightBefore); else - m_assembly.appendJump(stackHeightBefore - _function.returnVariables.size()); + m_assembly.appendJump(stackHeightBefore - static_cast(_function.returnVariables.size())); m_assembly.setStackHeight(stackHeightBefore); } @@ -683,7 +691,7 @@ void CodeTransform::generateAssignment(Identifier const& _variableName) if (auto var = m_scope->lookup(_variableName.name)) { Scope::Variable const& _var = std::get(*var); - if (int heightDiff = variableHeightDiff(_var, _variableName.name, true)) + if (size_t heightDiff = variableHeightDiff(_var, _variableName.name, true)) m_assembly.appendInstruction(evmasm::swapInstruction(heightDiff - 1)); m_assembly.appendInstruction(evmasm::Instruction::POP); decreaseReference(_variableName.name, _var); @@ -698,12 +706,12 @@ void CodeTransform::generateAssignment(Identifier const& _variableName) } } -int CodeTransform::variableHeightDiff(Scope::Variable const& _var, YulString _varName, bool _forSwap) +size_t CodeTransform::variableHeightDiff(Scope::Variable const& _var, YulString _varName, bool _forSwap) { yulAssert(m_context->variableStackHeights.count(&_var), ""); - int heightDiff = m_assembly.stackHeight() - m_context->variableStackHeights[&_var]; + size_t heightDiff = static_cast(m_assembly.stackHeight()) - m_context->variableStackHeights[&_var]; yulAssert(heightDiff > (_forSwap ? 1 : 0), "Negative stack difference for variable."); - int limit = _forSwap ? 17 : 16; + size_t limit = _forSwap ? 17 : 16; if (heightDiff > limit) { m_stackErrors.emplace_back(_varName, heightDiff - limit); @@ -723,4 +731,3 @@ void CodeTransform::expectDeposit(int _deposit, int _oldHeight) const { yulAssert(m_assembly.stackHeight() == _oldHeight + _deposit, "Invalid stack deposit."); } - diff --git a/libyul/backends/evm/EVMCodeTransform.h b/libyul/backends/evm/EVMCodeTransform.h index 6447aa7b1..3c9506b47 100644 --- a/libyul/backends/evm/EVMCodeTransform.h +++ b/libyul/backends/evm/EVMCodeTransform.h @@ -54,7 +54,7 @@ struct StackTooDeepError: virtual YulException struct CodeTransformContext { std::map functionEntryIDs; - std::map variableStackHeights; + std::map variableStackHeights; std::map variableReferences; struct JumpInfo @@ -200,7 +200,7 @@ private: /// Determines the stack height difference to the given variables. Throws /// if it is not yet in scope or the height difference is too large. Returns /// the (positive) stack height difference otherwise. - int variableHeightDiff(Scope::Variable const& _var, YulString _name, bool _forSwap); + size_t variableHeightDiff(Scope::Variable const& _var, YulString _name, bool _forSwap); void expectDeposit(int _deposit, int _oldHeight) const; diff --git a/libyul/backends/evm/EVMDialect.cpp b/libyul/backends/evm/EVMDialect.cpp index b5b5eda6e..6875df234 100644 --- a/libyul/backends/evm/EVMDialect.cpp +++ b/libyul/backends/evm/EVMDialect.cpp @@ -63,8 +63,8 @@ pair createEVMFunction( evmasm::InstructionInfo info = evmasm::instructionInfo(_instruction); BuiltinFunctionForEVM f; f.name = YulString{_name}; - f.parameters.resize(info.args); - f.returns.resize(info.ret); + f.parameters.resize(static_cast(info.args)); + f.returns.resize(static_cast(info.ret)); f.sideEffects = EVMDialect::sideEffectsOfInstruction(_instruction); f.controlFlowSideEffects.terminates = evmasm::SemanticInformation::terminatesControlFlow(_instruction); f.controlFlowSideEffects.reverts = evmasm::SemanticInformation::reverts(_instruction); diff --git a/libyul/backends/evm/EVMMetrics.cpp b/libyul/backends/evm/EVMMetrics.cpp index 4d1103578..f3508afb3 100644 --- a/libyul/backends/evm/EVMMetrics.cpp +++ b/libyul/backends/evm/EVMMetrics.cpp @@ -91,7 +91,11 @@ void GasMeterVisitor::operator()(Literal const& _lit) m_runGas += evmasm::GasMeter::runGas(evmasm::Instruction::PUSH1); m_dataGas += singleByteDataGas() + - size_t(evmasm::GasMeter::dataGas(toCompactBigEndian(valueOfLiteral(_lit), 1), m_isCreation, m_dialect.evmVersion())); + static_cast(evmasm::GasMeter::dataGas( + toCompactBigEndian(valueOfLiteral(_lit), 1), + m_isCreation, + m_dialect.evmVersion() + )); } void GasMeterVisitor::operator()(Identifier const&) diff --git a/libyul/backends/wasm/BinaryTransform.cpp b/libyul/backends/wasm/BinaryTransform.cpp index b305b9c55..82de96b51 100644 --- a/libyul/backends/wasm/BinaryTransform.cpp +++ b/libyul/backends/wasm/BinaryTransform.cpp @@ -376,12 +376,12 @@ bytes BinaryTransform::operator()(BuiltinCall const& _call) if (_call.functionName == "dataoffset") { string name = get(_call.arguments.at(0)).value; - return toBytes(Opcode::I64Const) + lebEncodeSigned(m_subModulePosAndSize.at(name).first); + return toBytes(Opcode::I64Const) + lebEncodeSigned(static_cast(m_subModulePosAndSize.at(name).first)); } else if (_call.functionName == "datasize") { string name = get(_call.arguments.at(0)).value; - return toBytes(Opcode::I64Const) + lebEncodeSigned(m_subModulePosAndSize.at(name).second); + return toBytes(Opcode::I64Const) + lebEncodeSigned(static_cast(m_subModulePosAndSize.at(name).second)); } bytes args = visit(_call.arguments); diff --git a/libyul/backends/wasm/WordSizeTransform.cpp b/libyul/backends/wasm/WordSizeTransform.cpp index edcc08923..473f7324f 100644 --- a/libyul/backends/wasm/WordSizeTransform.cpp +++ b/libyul/backends/wasm/WordSizeTransform.cpp @@ -112,7 +112,7 @@ void WordSizeTransform::operator()(Block& _block) yulAssert(varDecl.variables.size() == 1, ""); auto newLhs = generateU64IdentifierNames(varDecl.variables[0].name); vector ret; - for (int i = 0; i < 3; i++) + for (size_t i = 0; i < 3; i++) ret.emplace_back(VariableDeclaration{ varDecl.location, {TypedName{varDecl.location, newLhs[i], m_targetDialect.defaultType}}, @@ -143,7 +143,7 @@ void WordSizeTransform::operator()(Block& _block) auto newRhs = expandValue(*varDecl.value); auto newLhs = generateU64IdentifierNames(varDecl.variables[0].name); vector ret; - for (int i = 0; i < 4; i++) + for (size_t i = 0; i < 4; i++) ret.emplace_back(VariableDeclaration{ varDecl.location, {TypedName{varDecl.location, newLhs[i], m_targetDialect.defaultType}}, @@ -172,7 +172,7 @@ void WordSizeTransform::operator()(Block& _block) yulAssert(assignment.variableNames.size() == 1, ""); auto newLhs = generateU64IdentifierNames(assignment.variableNames[0].name); vector ret; - for (int i = 0; i < 3; i++) + for (size_t i = 0; i < 3; i++) ret.emplace_back(Assignment{ assignment.location, {Identifier{assignment.location, newLhs[i]}}, @@ -203,7 +203,7 @@ void WordSizeTransform::operator()(Block& _block) auto newRhs = expandValue(*assignment.value); YulString lhsName = assignment.variableNames[0].name; vector ret; - for (int i = 0; i < 4; i++) + for (size_t i = 0; i < 4; i++) ret.emplace_back(Assignment{ assignment.location, {Identifier{assignment.location, m_variableMapping.at(lhsName)[i]}}, @@ -382,7 +382,7 @@ std::vector WordSizeTransform::handleSwitch(Switch& _switch) array WordSizeTransform::generateU64IdentifierNames(YulString const& _s) { yulAssert(m_variableMapping.find(_s) == m_variableMapping.end(), ""); - for (int i = 0; i < 4; i++) + for (size_t i = 0; i < 4; i++) m_variableMapping[_s][i] = m_nameDispenser.newName(YulString{_s.str() + "_" + to_string(i)}); return m_variableMapping[_s]; } @@ -392,19 +392,20 @@ array, 4> WordSizeTransform::expandValue(Expression const array, 4> ret; if (holds_alternative(_e)) { - Identifier const& id = std::get(_e); - for (int i = 0; i < 4; i++) + auto const& id = std::get(_e); + for (size_t i = 0; i < 4; i++) ret[i] = make_unique(Identifier{id.location, m_variableMapping.at(id.name)[i]}); } else if (holds_alternative(_e)) { - Literal const& lit = std::get(_e); + auto const& lit = std::get(_e); u256 val = valueOfLiteral(lit); - for (int i = 3; i >= 0; i--) + for (size_t exprIndex = 0; exprIndex < 4; ++exprIndex) { + size_t exprIndexReverse = 3 - exprIndex; u256 currentVal = val & std::numeric_limits::max(); val >>= 64; - ret[i] = make_unique( + ret[exprIndexReverse] = make_unique( Literal{ lit.location, LiteralKind::Number, @@ -426,4 +427,3 @@ vector WordSizeTransform::expandValueToVector(Expression const& _e) ret.emplace_back(std::move(*val)); return ret; } - diff --git a/libyul/optimiser/DeadCodeEliminator.cpp b/libyul/optimiser/DeadCodeEliminator.cpp index 890161bf0..2416af514 100644 --- a/libyul/optimiser/DeadCodeEliminator.cpp +++ b/libyul/optimiser/DeadCodeEliminator.cpp @@ -51,10 +51,10 @@ void DeadCodeEliminator::operator()(Block& _block) tie(controlFlowChange, index) = TerminationFinder{m_dialect}.firstUnconditionalControlFlowChange(_block.statements); // Erase everything after the terminating statement that is not a function definition. - if (controlFlowChange != TerminationFinder::ControlFlow::FlowOut && index != size_t(-1)) + if (controlFlowChange != TerminationFinder::ControlFlow::FlowOut && index != std::numeric_limits::max()) _block.statements.erase( remove_if( - _block.statements.begin() + index + 1, + _block.statements.begin() + static_cast(index) + 1, _block.statements.end(), [] (Statement const& _s) { return !holds_alternative(_s); } ), @@ -63,4 +63,3 @@ void DeadCodeEliminator::operator()(Block& _block) ASTModifier::operator()(_block); } - diff --git a/libyul/optimiser/ExpressionJoiner.cpp b/libyul/optimiser/ExpressionJoiner.cpp index ba38fa86e..45c23dcc3 100644 --- a/libyul/optimiser/ExpressionJoiner.cpp +++ b/libyul/optimiser/ExpressionJoiner.cpp @@ -119,7 +119,7 @@ void ExpressionJoiner::decrementLatestStatementPointer() void ExpressionJoiner::resetLatestStatementPointer() { m_currentBlock = nullptr; - m_latestStatementInBlock = size_t(-1); + m_latestStatementInBlock = numeric_limits::max(); } Statement* ExpressionJoiner::latestStatement() diff --git a/libyul/optimiser/Semantics.cpp b/libyul/optimiser/Semantics.cpp index a6f41b844..f9d831b7a 100644 --- a/libyul/optimiser/Semantics.cpp +++ b/libyul/optimiser/Semantics.cpp @@ -180,7 +180,7 @@ pair TerminationFinder::firstUncondition if (controlFlow != ControlFlow::FlowOut) return {controlFlow, i}; } - return {ControlFlow::FlowOut, size_t(-1)}; + return {ControlFlow::FlowOut, numeric_limits::max()}; } TerminationFinder::ControlFlow TerminationFinder::controlFlowKind(Statement const& _statement) diff --git a/libyul/optimiser/StackCompressor.cpp b/libyul/optimiser/StackCompressor.cpp index cfb2fef82..d011c64b8 100644 --- a/libyul/optimiser/StackCompressor.cpp +++ b/libyul/optimiser/StackCompressor.cpp @@ -178,14 +178,14 @@ bool StackCompressor::run( eliminateVariables( _dialect, std::get(_object.code->statements.at(0)), - stackSurplus.at({}), + static_cast(stackSurplus.at({})), allowMSizeOptimzation ); } for (size_t i = 1; i < _object.code->statements.size(); ++i) { - FunctionDefinition& fun = std::get(_object.code->statements[i]); + auto& fun = std::get(_object.code->statements[i]); if (!stackSurplus.count(fun.name)) continue; @@ -193,7 +193,7 @@ bool StackCompressor::run( eliminateVariables( _dialect, fun, - stackSurplus.at(fun.name), + static_cast(stackSurplus.at(fun.name)), allowMSizeOptimzation ); }