diff --git a/libsolidity/analysis/OverrideChecker.cpp b/libsolidity/analysis/OverrideChecker.cpp index 89f9a6637..c488fd278 100644 --- a/libsolidity/analysis/OverrideChecker.cpp +++ b/libsolidity/analysis/OverrideChecker.cpp @@ -68,7 +68,7 @@ struct OverrideGraph std::map nodes; std::map nodeInv; std::map> edges; - int numNodes = 2; + size_t numNodes = 2; void addEdge(int _a, int _b) { edges[_a].insert(_b); @@ -82,7 +82,7 @@ private: auto it = nodes.find(_function); if (it != nodes.end()) return it->second; - int currentNode = numNodes++; + int currentNode = static_cast(numNodes++); nodes[_function] = currentNode; nodeInv[currentNode] = _function; if (_function.overrides()) @@ -116,21 +116,24 @@ private: std::vector m_parent = std::vector(m_graph.numNodes, -1); std::set m_cutVertices{}; - void run(int _u = 0, int _depth = 0) + void run(size_t _u = 0, size_t _depth = 0) { m_visited.at(_u) = true; - m_depths.at(_u) = m_low.at(_u) = _depth; - for (int v: m_graph.edges.at(_u)) - if (!m_visited.at(v)) + m_depths.at(_u) = m_low.at(_u) = static_cast(_depth); + for (int const v: m_graph.edges.at(static_cast(_u))) + { + auto const vInd = static_cast(v); + if (!m_visited.at(vInd)) { - m_parent[v] = _u; - run(v, _depth + 1); - if (m_low[v] >= m_depths[_u] && m_parent[_u] != -1) - m_cutVertices.insert(m_graph.nodeInv.at(_u)); - m_low[_u] = min(m_low[_u], m_low[v]); + m_parent[vInd] = static_cast(_u); + run(vInd, _depth + 1); + if (m_low[vInd] >= m_depths[_u] && m_parent[_u] != -1) + m_cutVertices.insert(m_graph.nodeInv.at(static_cast(_u))); + m_low[_u] = min(m_low[_u], m_low[vInd]); } else if (v != m_parent[_u]) - m_low[_u] = min(m_low[_u], m_depths[v]); + m_low[_u] = min(m_low[_u], m_depths[vInd]); + } } }; @@ -213,7 +216,7 @@ bool OverrideProxy::CompareBySignature::operator()(OverrideProxy const& _a, Over size_t OverrideProxy::id() const { return std::visit(GenericVisitor{ - [&](auto const* _item) -> size_t { return _item->id(); } + [&](auto const* _item) -> size_t { return static_cast(_item->id()); } }, m_item); } diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index bdf27585d..c308fadd8 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -666,7 +666,7 @@ bool TypeChecker::visit(InlineAssembly const& _inlineAssembly) { auto ref = _inlineAssembly.annotation().externalReferences.find(&_identifier); if (ref == _inlineAssembly.annotation().externalReferences.end()) - return size_t(-1); + return numeric_limits::max(); Declaration const* declaration = ref->second.declaration; solAssert(!!declaration, ""); bool requiresStorage = ref->second.isSlot || ref->second.isOffset; @@ -676,7 +676,7 @@ bool TypeChecker::visit(InlineAssembly const& _inlineAssembly) if (var->immutable()) { m_errorReporter.typeError(3773_error, _identifier.location, "Assembly access to immutable variables is not supported."); - return size_t(-1); + return numeric_limits::max(); } if (var->isConstant()) { @@ -685,17 +685,17 @@ bool TypeChecker::visit(InlineAssembly const& _inlineAssembly) if (var && !var->value()) { m_errorReporter.typeError(3224_error, _identifier.location, "Constant has no value."); - return size_t(-1); + return numeric_limits::max(); } else if (_context == yul::IdentifierContext::LValue) { m_errorReporter.typeError(6252_error, _identifier.location, "Constant variables cannot be assigned to."); - return size_t(-1); + return numeric_limits::max(); } else if (requiresStorage) { m_errorReporter.typeError(6617_error, _identifier.location, "The suffixes _offset and _slot can only be used on non-constant storage variables."); - return size_t(-1); + return numeric_limits::max(); } else if (var && var->value() && !var->value()->annotation().type && !dynamic_cast(var->value().get())) { @@ -723,19 +723,19 @@ bool TypeChecker::visit(InlineAssembly const& _inlineAssembly) if (!var->isStateVariable() && !var->type()->dataStoredIn(DataLocation::Storage)) { m_errorReporter.typeError(3622_error, _identifier.location, "The suffixes _offset and _slot can only be used on storage variables."); - return size_t(-1); + return numeric_limits::max(); } else if (_context == yul::IdentifierContext::LValue) { if (var->isStateVariable()) { m_errorReporter.typeError(4713_error, _identifier.location, "State variables cannot be assigned to - you have to use \"sstore()\"."); - return size_t(-1); + return numeric_limits::max(); } else if (ref->second.isOffset) { m_errorReporter.typeError(9739_error, _identifier.location, "Only _slot can be assigned to."); - return size_t(-1); + return numeric_limits::max(); } else solAssert(ref->second.isSlot, ""); @@ -744,12 +744,12 @@ bool TypeChecker::visit(InlineAssembly const& _inlineAssembly) else if (!var->isConstant() && var->isStateVariable()) { m_errorReporter.typeError(1408_error, _identifier.location, "Only local variables are supported. To access storage variables, use the _slot and _offset suffixes."); - return size_t(-1); + return numeric_limits::max(); } else if (var->type()->dataStoredIn(DataLocation::Storage)) { m_errorReporter.typeError(9068_error, _identifier.location, "You have to use the _slot or _offset suffix to access storage reference variables."); - return size_t(-1); + return numeric_limits::max(); } else if (var->type()->sizeOnStack() != 1) { @@ -757,21 +757,21 @@ bool TypeChecker::visit(InlineAssembly const& _inlineAssembly) m_errorReporter.typeError(2370_error, _identifier.location, "Call data elements cannot be accessed directly. Copy to a local variable first or use \"calldataload\" or \"calldatacopy\" with manually determined offsets and sizes."); else m_errorReporter.typeError(9857_error, _identifier.location, "Only types that use one stack slot are supported."); - return size_t(-1); + return numeric_limits::max(); } } else if (requiresStorage) { m_errorReporter.typeError(7944_error, _identifier.location, "The suffixes _offset and _slot can only be used on storage variables."); - return size_t(-1); + return numeric_limits::max(); } else if (_context == yul::IdentifierContext::LValue) { if (dynamic_cast(declaration)) - return size_t(-1); + return numeric_limits::max(); m_errorReporter.typeError(1990_error, _identifier.location, "Only local variables can be assigned to in inline assembly."); - return size_t(-1); + return numeric_limits::max(); } if (_context == yul::IdentifierContext::RValue) @@ -780,7 +780,7 @@ bool TypeChecker::visit(InlineAssembly const& _inlineAssembly) if (dynamic_cast(declaration)) { m_errorReporter.declarationError(2025_error, _identifier.location, "Access to functions is not allowed in inline assembly."); - return size_t(-1); + return numeric_limits::max(); } else if (dynamic_cast(declaration)) { @@ -790,11 +790,11 @@ bool TypeChecker::visit(InlineAssembly const& _inlineAssembly) if (!contract->isLibrary()) { m_errorReporter.typeError(4977_error, _identifier.location, "Expected a library."); - return size_t(-1); + return numeric_limits::max(); } } else - return size_t(-1); + return numeric_limits::max(); } ref->second.valueSize = 1; return size_t(1); diff --git a/libsolidity/ast/AST.cpp b/libsolidity/ast/AST.cpp index c11a05a02..3492bfc45 100644 --- a/libsolidity/ast/AST.cpp +++ b/libsolidity/ast/AST.cpp @@ -38,7 +38,7 @@ using namespace solidity; using namespace solidity::frontend; ASTNode::ASTNode(int64_t _id, SourceLocation _location): - m_id(_id), + m_id(static_cast(_id)), m_location(std::move(_location)) { } diff --git a/libsolidity/ast/AST.h b/libsolidity/ast/AST.h index c1c02b2bb..c6c560988 100644 --- a/libsolidity/ast/AST.h +++ b/libsolidity/ast/AST.h @@ -88,7 +88,7 @@ public: virtual ~ASTNode() {} /// @returns an identifier of this AST node that is unique for a single compilation run. - int64_t id() const { return m_id; } + int64_t id() const { return int64_t(m_id); } virtual void accept(ASTVisitor& _visitor) = 0; virtual void accept(ASTConstVisitor& _visitor) const = 0; diff --git a/libsolidity/ast/ASTJsonConverter.cpp b/libsolidity/ast/ASTJsonConverter.cpp index 8da1dddd7..219151f89 100644 --- a/libsolidity/ast/ASTJsonConverter.cpp +++ b/libsolidity/ast/ASTJsonConverter.cpp @@ -37,6 +37,7 @@ #include #include #include +#include using namespace std; using namespace solidity::langutil; @@ -134,7 +135,7 @@ size_t ASTJsonConverter::sourceIndexFromLocation(SourceLocation const& _location if (_location.source && m_sourceIndices.count(_location.source->name())) return m_sourceIndices.at(_location.source->name()); else - return size_t(-1); + return numeric_limits::max(); } string ASTJsonConverter::sourceLocationToString(SourceLocation const& _location) const diff --git a/libsolidity/ast/ASTJsonImporter.cpp b/libsolidity/ast/ASTJsonImporter.cpp index 97e3ba964..65f9fa718 100644 --- a/libsolidity/ast/ASTJsonImporter.cpp +++ b/libsolidity/ast/ASTJsonImporter.cpp @@ -92,7 +92,7 @@ SourceLocation const ASTJsonImporter::createSourceLocation(Json::Value const& _n { astAssert(member(_node, "src").isString(), "'src' must be a string"); - return solidity::langutil::parseSourceLocation(_node["src"].asString(), m_currentSourceName, int(m_sourceLocations.size())); + return solidity::langutil::parseSourceLocation(_node["src"].asString(), m_currentSourceName, m_sourceLocations.size()); } template diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index 66681ea10..669e54d0e 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -773,7 +773,7 @@ tuple RationalNumberType::parseRational(string const& _value) denominator = bigint(string(fractionalBegin, _value.end())); denominator /= boost::multiprecision::pow( bigint(10), - distance(radixPoint + 1, _value.end()) + static_cast(distance(radixPoint + 1, _value.end())) ); numerator = bigint(string(_value.begin(), radixPoint)); value = numerator + denominator; @@ -1065,7 +1065,7 @@ TypeResult RationalNumberType::binaryOperatorResult(Token _operator, Type const* if (_base == 1) return 1; else if (_base == -1) - return 1 - 2 * int(_exponent & 1); + return 1 - 2 * static_cast(_exponent & 1); else return boost::multiprecision::pow(_base, _exponent); }; @@ -1171,7 +1171,7 @@ string RationalNumberType::bigintToReadableString(bigint const& _num) string str = _num.str(); if (str.size() > 32) { - int omitted = str.size() - 8; + size_t omitted = str.size() - 8; str = str.substr(0, 4) + "...(" + to_string(omitted) + " digits omitted)..." + str.substr(str.size() - 4, 4); } return str; @@ -1201,7 +1201,7 @@ u256 RationalNumberType::literalValue(Literal const*) const { auto fixed = fixedPointType(); solAssert(fixed, "Rational number cannot be represented as fixed point type."); - int fractionalDigits = fixed->fractionalDigits(); + unsigned fractionalDigits = fixed->fractionalDigits(); shiftedValue = m_value.numerator() * boost::multiprecision::pow(bigint(10), fractionalDigits) / m_value.denominator(); } @@ -1291,7 +1291,7 @@ StringLiteralType::StringLiteralType(string _value): BoolResult StringLiteralType::isImplicitlyConvertibleTo(Type const& _convertTo) const { if (auto fixedBytes = dynamic_cast(&_convertTo)) - return size_t(fixedBytes->numBytes()) >= m_value.size(); + return static_cast(fixedBytes->numBytes()) >= m_value.size(); else if (auto arrayType = dynamic_cast(&_convertTo)) return arrayType->isByteArray() && diff --git a/libsolidity/codegen/ABIFunctions.cpp b/libsolidity/codegen/ABIFunctions.cpp index 189fba165..9f244fdb1 100644 --- a/libsolidity/codegen/ABIFunctions.cpp +++ b/libsolidity/codegen/ABIFunctions.cpp @@ -725,7 +725,7 @@ string ABIFunctions::abiEncodingFunctionCompactStorageArray( size_t itemsPerSlot = 32 / storageBytes; solAssert(itemsPerSlot > 0, ""); // The number of elements we need to handle manually after the loop. - size_t spill = size_t(_from.length() % itemsPerSlot); + size_t spill = static_cast(_from.length() % itemsPerSlot); Whiskers templ( R"( // -> diff --git a/libsolidity/codegen/ArrayUtils.cpp b/libsolidity/codegen/ArrayUtils.cpp index 732deca6f..9f12f648f 100644 --- a/libsolidity/codegen/ArrayUtils.cpp +++ b/libsolidity/codegen/ArrayUtils.cpp @@ -56,7 +56,7 @@ void ArrayUtils::copyArrayToStorage(ArrayType const& _targetType, ArrayType cons bool directCopy = sourceIsStorage && sourceBaseType->isValueType() && *sourceBaseType == *targetBaseType; bool haveByteOffsetSource = !directCopy && sourceIsStorage && sourceBaseType->storageBytes() <= 16; bool haveByteOffsetTarget = !directCopy && targetBaseType->storageBytes() <= 16; - unsigned byteOffsetSize = (haveByteOffsetSource ? 1 : 0) + (haveByteOffsetTarget ? 1 : 0); + unsigned byteOffsetSize = (haveByteOffsetSource ? 1u : 0u) + (haveByteOffsetTarget ? 1u : 0u); // stack: source_ref [source_length] target_ref // store target_ref diff --git a/libsolidity/codegen/CompilerContext.cpp b/libsolidity/codegen/CompilerContext.cpp index 9e2c0663b..fea449f7f 100644 --- a/libsolidity/codegen/CompilerContext.cpp +++ b/libsolidity/codegen/CompilerContext.cpp @@ -133,7 +133,7 @@ void CompilerContext::callLowLevelFunction( *this << lowLevelFunctionTag(_name, _inArgs, _outArgs, _generator); appendJump(evmasm::AssemblyItem::JumpType::IntoFunction); - adjustStackOffset(int(_outArgs) - 1 - _inArgs); + adjustStackOffset(static_cast(_outArgs) - 1 - static_cast(_inArgs)); *this << retTag.tag(); } @@ -147,7 +147,7 @@ void CompilerContext::callYulFunction( auto const retTag = pushNewTag(); CompilerUtils(*this).moveIntoStack(_inArgs); appendJumpTo(namedTag(_name)); - adjustStackOffset(int(_outArgs) - 1 - _inArgs); + adjustStackOffset(static_cast(_outArgs) - 1 - static_cast(_inArgs)); *this << retTag.tag(); } @@ -181,7 +181,7 @@ void CompilerContext::appendMissingLowLevelFunctions() tie(name, inArgs, outArgs, generator) = m_lowLevelFunctionGenerationQueue.front(); m_lowLevelFunctionGenerationQueue.pop(); - setStackOffset(inArgs + 1); + setStackOffset(static_cast(inArgs) + 1); *this << m_lowLevelFunctions.at(name).tag(); generator(*this); CompilerUtils(*this).moveToStackTop(outArgs); @@ -298,12 +298,12 @@ unsigned CompilerContext::baseStackOffsetOfVariable(Declaration const& _declarat unsigned CompilerContext::baseToCurrentStackOffset(unsigned _baseOffset) const { - return m_asm->deposit() - _baseOffset - 1; + return static_cast(m_asm->deposit()) - _baseOffset - 1; } unsigned CompilerContext::currentToBaseStackOffset(unsigned _offset) const { - return m_asm->deposit() - _offset - 1; + return static_cast(m_asm->deposit()) - _offset - 1; } pair CompilerContext::storageLocationOfVariable(Declaration const& _declaration) const @@ -371,7 +371,7 @@ void CompilerContext::appendInlineAssembly( OptimiserSettings const& _optimiserSettings ) { - int startStackHeight = stackHeight(); + unsigned startStackHeight = stackHeight(); set externallyUsedIdentifiers; for (auto const& fun: _externallyUsedFunctions) @@ -387,9 +387,9 @@ void CompilerContext::appendInlineAssembly( ) -> size_t { if (_insideFunction) - return size_t(-1); + return numeric_limits::max(); auto it = std::find(_localVariables.begin(), _localVariables.end(), _identifier.name.str()); - return it == _localVariables.end() ? size_t(-1) : 1; + return it == _localVariables.end() ? numeric_limits::max() : 1; }; identifierAccess.generateCode = [&]( yul::Identifier const& _identifier, @@ -399,8 +399,8 @@ void CompilerContext::appendInlineAssembly( { auto it = std::find(_localVariables.begin(), _localVariables.end(), _identifier.name.str()); solAssert(it != _localVariables.end(), ""); - int stackDepth = _localVariables.end() - it; - int stackDiff = _assembly.stackHeight() - startStackHeight + stackDepth; + auto stackDepth = static_cast(distance(it, _localVariables.end())); + size_t stackDiff = static_cast(_assembly.stackHeight()) - startStackHeight + stackDepth; if (_context == yul::IdentifierContext::LValue) stackDiff -= 1; if (stackDiff < 1 || stackDiff > 16) diff --git a/libsolidity/codegen/CompilerContext.h b/libsolidity/codegen/CompilerContext.h index 51d3afe1c..c32b51406 100644 --- a/libsolidity/codegen/CompilerContext.h +++ b/libsolidity/codegen/CompilerContext.h @@ -377,7 +377,7 @@ private: /// The runtime context if in Creation mode, this is used for generating tags that would be stored into the storage and then used at runtime. CompilerContext *m_runtimeContext; /// The index of the runtime subroutine. - size_t m_runtimeSub = -1; + size_t m_runtimeSub = std::numeric_limits::max(); /// An index of low-level function labels by name. std::map m_lowLevelFunctions; /// Collector for yul functions. diff --git a/libsolidity/codegen/CompilerUtils.cpp b/libsolidity/codegen/CompilerUtils.cpp index 2735c2fce..c3e81d13a 100644 --- a/libsolidity/codegen/CompilerUtils.cpp +++ b/libsolidity/codegen/CompilerUtils.cpp @@ -1351,7 +1351,7 @@ void CompilerUtils::popAndJump(unsigned _toHeight, evmasm::AssemblyItem const& _ unsigned amount = m_context.stackHeight() - _toHeight; popStackSlots(amount); m_context.appendJumpTo(_jumpTo); - m_context.adjustStackOffset(amount); + m_context.adjustStackOffset(static_cast(amount)); } unsigned CompilerUtils::sizeOnStack(vector const& _variableTypes) @@ -1436,7 +1436,7 @@ unsigned CompilerUtils::loadFromMemoryHelper(Type const& _type, bool _fromCallda { bool leftAligned = _type.category() == Type::Category::FixedBytes; // add leading or trailing zeros by dividing/multiplying depending on alignment - int shiftFactor = (32 - numBytes) * 8; + unsigned shiftFactor = (32 - numBytes) * 8; rightShiftNumberOnStack(shiftFactor); if (leftAligned) { diff --git a/libsolidity/codegen/ContractCompiler.cpp b/libsolidity/codegen/ContractCompiler.cpp index 269d9a5bf..6f8603a51 100644 --- a/libsolidity/codegen/ContractCompiler.cpp +++ b/libsolidity/codegen/ContractCompiler.cpp @@ -185,7 +185,7 @@ size_t ContractCompiler::packIntoContractCreator(ContractDefinition const& _cont CompilerContext::LocationSetter locationSetter(m_context, _contract); m_context << deployRoutine; - solAssert(m_context.runtimeSub() != size_t(-1), "Runtime sub not registered"); + solAssert(m_context.runtimeSub() != numeric_limits::max(), "Runtime sub not registered"); ContractType contractType(_contract); auto const& immutables = contractType.immutableVariables(); @@ -221,7 +221,7 @@ size_t ContractCompiler::deployLibrary(ContractDefinition const& _contract) CompilerContext::LocationSetter locationSetter(m_context, _contract); - solAssert(m_context.runtimeSub() != size_t(-1), "Runtime sub not registered"); + solAssert(m_context.runtimeSub() != numeric_limits::max(), "Runtime sub not registered"); m_context.pushSubroutineSize(m_context.runtimeSub()); m_context.pushSubroutineOffset(m_context.runtimeSub()); // This code replaces the address added by appendDeployTimeAddress(). @@ -349,11 +349,11 @@ void ContractCompiler::appendInternalSelector( m_context << dupInstruction(1) << u256(FixedHash<4>::Arith(pivot)) << Instruction::GT; evmasm::AssemblyItem lessTag{m_context.appendConditionalJump()}; // Here, we have funid >= pivot - vector> larger{_ids.begin() + pivotIndex, _ids.end()}; + vector> larger{_ids.begin() + static_cast(pivotIndex), _ids.end()}; appendInternalSelector(_entryPoints, larger, _notFoundTag, _runs); m_context << lessTag; // Here, we have funid < pivot - vector> smaller{_ids.begin(), _ids.begin() + pivotIndex}; + vector> smaller{_ids.begin(), _ids.begin() + static_cast(pivotIndex)}; appendInternalSelector(_entryPoints, smaller, _notFoundTag, _runs); } else @@ -512,8 +512,8 @@ void ContractCompiler::appendFunctionSelector(ContractDefinition const& _contrac m_context << returnTag; // Return tag and input parameters get consumed. m_context.adjustStackOffset( - CompilerUtils(m_context).sizeOnStack(functionType->returnParameterTypes()) - - CompilerUtils(m_context).sizeOnStack(functionType->parameterTypes()) - + static_cast(CompilerUtils::sizeOnStack(functionType->returnParameterTypes())) - + static_cast(CompilerUtils::sizeOnStack(functionType->parameterTypes())) - 1 ); // Consumes the return parameters. @@ -589,7 +589,7 @@ bool ContractCompiler::visit(FunctionDefinition const& _function) unsigned parametersSize = CompilerUtils::sizeOnStack(_function.parameters()); if (!_function.isConstructor()) // adding 1 for return address. - m_context.adjustStackOffset(parametersSize + 1); + m_context.adjustStackOffset(static_cast(parametersSize) + 1); for (ASTPointer const& variable: _function.parameters()) { m_context.addVariable(*variable, parametersSize); @@ -609,7 +609,7 @@ bool ContractCompiler::visit(FunctionDefinition const& _function) m_breakTags.clear(); m_continueTags.clear(); m_currentFunction = &_function; - m_modifierDepth = -1; + m_modifierDepth = numeric_limits::max(); m_scopeStackHeight.clear(); m_context.setModifierDepth(0); @@ -627,10 +627,10 @@ bool ContractCompiler::visit(FunctionDefinition const& _function) unsigned const c_returnValuesSize = CompilerUtils::sizeOnStack(_function.returnParameters()); vector stackLayout; - stackLayout.push_back(c_returnValuesSize); // target of return address + stackLayout.push_back(static_cast(c_returnValuesSize)); // target of return address stackLayout += vector(c_argumentsSize, -1); // discard all arguments - for (unsigned i = 0; i < c_returnValuesSize; ++i) - stackLayout.push_back(i); + for (size_t i = 0; i < c_returnValuesSize; ++i) + stackLayout.push_back(static_cast(i)); if (stackLayout.size() > 17) BOOST_THROW_EXCEPTION( @@ -638,7 +638,7 @@ bool ContractCompiler::visit(FunctionDefinition const& _function) errinfo_sourceLocation(_function.location()) << errinfo_comment("Stack too deep, try removing local variables.") ); - while (stackLayout.back() != int(stackLayout.size() - 1)) + while (stackLayout.back() != static_cast(stackLayout.size() - 1)) if (stackLayout.back() < 0) { m_context << Instruction::POP; @@ -646,11 +646,11 @@ bool ContractCompiler::visit(FunctionDefinition const& _function) } else { - m_context << swapInstruction(stackLayout.size() - stackLayout.back() - 1); - swap(stackLayout[stackLayout.back()], stackLayout.back()); + m_context << swapInstruction(stackLayout.size() - static_cast(stackLayout.back()) - 1); + swap(stackLayout[static_cast(stackLayout.back())], stackLayout.back()); } - for (int i = 0; i < int(stackLayout.size()); ++i) - if (stackLayout[i] != i) + for (size_t i = 0; i < stackLayout.size(); ++i) + if (stackLayout[i] != static_cast(i)) solAssert(false, "Invalid stack layout on cleanup."); for (ASTPointer const& variable: _function.parameters() + _function.returnParameters()) @@ -677,7 +677,7 @@ bool ContractCompiler::visit(InlineAssembly const& _inlineAssembly) { auto ref = _inlineAssembly.annotation().externalReferences.find(&_identifier); if (ref == _inlineAssembly.annotation().externalReferences.end()) - return size_t(-1); + return numeric_limits::max(); return ref->second.valueSize; }; identifierAccess.generateCode = [&](yul::Identifier const& _identifier, yul::IdentifierContext _context, yul::AbstractAssembly& _assembly) @@ -696,7 +696,7 @@ bool ContractCompiler::visit(InlineAssembly const& _inlineAssembly) functionDef = &functionDef->resolveVirtual(m_context.mostDerivedContract()); auto functionEntryLabel = m_context.functionEntryLabel(*functionDef).pushTag(); solAssert(functionEntryLabel.data() <= std::numeric_limits::max(), ""); - _assembly.appendLabelReference(size_t(functionEntryLabel.data())); + _assembly.appendLabelReference(static_cast(functionEntryLabel.data())); // If there is a runtime context, we have to merge both labels into the same // stack slot in case we store it in storage. if (CompilerContext* rtc = m_context.runtimeContext()) @@ -705,7 +705,7 @@ bool ContractCompiler::visit(InlineAssembly const& _inlineAssembly) _assembly.appendInstruction(Instruction::MUL); auto runtimeEntryLabel = rtc->functionEntryLabel(*functionDef).toSubAssemblyTag(m_context.runtimeSub()); solAssert(runtimeEntryLabel.data() <= std::numeric_limits::max(), ""); - _assembly.appendLabelReference(size_t(runtimeEntryLabel.data())); + _assembly.appendLabelReference(static_cast(runtimeEntryLabel.data())); _assembly.appendInstruction(Instruction::OR); } } @@ -772,7 +772,7 @@ bool ContractCompiler::visit(InlineAssembly const& _inlineAssembly) } else if (m_context.isLocalVariable(decl)) { - int stackDiff = _assembly.stackHeight() - m_context.baseStackOffsetOfVariable(*variable); + unsigned stackDiff = static_cast(_assembly.stackHeight()) - m_context.baseStackOffsetOfVariable(*variable); if (ref->second.isSlot || ref->second.isOffset) { solAssert(variable->type()->dataStoredIn(DataLocation::Storage), ""); @@ -816,7 +816,7 @@ bool ContractCompiler::visit(InlineAssembly const& _inlineAssembly) } else solAssert(false, "Invalid declaration type."); - solAssert(_assembly.stackHeight() - depositBefore == int(ref->second.valueSize), ""); + solAssert(_assembly.stackHeight() - depositBefore == static_cast(ref->second.valueSize), ""); } else { @@ -828,7 +828,7 @@ bool ContractCompiler::visit(InlineAssembly const& _inlineAssembly) "Can only assign to stack variables in inline assembly." ); solAssert(variable->type()->sizeOnStack() == 1, ""); - int stackDiff = _assembly.stackHeight() - m_context.baseStackOffsetOfVariable(*variable) - 1; + unsigned stackDiff = static_cast(_assembly.stackHeight()) - m_context.baseStackOffsetOfVariable(*variable) - 1; if (stackDiff > 16 || stackDiff < 1) BOOST_THROW_EXCEPTION( CompilerError() << @@ -875,7 +875,7 @@ bool ContractCompiler::visit(InlineAssembly const& _inlineAssembly) false, m_optimiserSettings.optimizeStackAllocation ); - m_context.setStackOffset(startStackHeight); + m_context.setStackOffset(static_cast(startStackHeight)); return false; } @@ -914,7 +914,7 @@ bool ContractCompiler::visit(TryStatement const& _tryStatement) solAssert(params[i] && exprTypes[i] && *params[i]->annotation().type == *exprTypes[i], ""); } else - CompilerUtils(m_context).popStackSlots(returnSize); + CompilerUtils(m_context).popStackSlots(static_cast(returnSize)); _tryStatement.clauses().front()->accept(*this); } @@ -937,7 +937,7 @@ void ContractCompiler::handleCatch(vector> const& _ca else solAssert(false, ""); - solAssert(_catchClauses.size() == size_t(1 + (structured ? 1 : 0) + (fallback ? 1 : 0)), ""); + solAssert(_catchClauses.size() == 1ul + (structured ? 1 : 0) + (fallback ? 1 : 0), ""); evmasm::AssemblyItem endTag = m_context.newTag(); evmasm::AssemblyItem fallbackTag = m_context.newTag(); diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp index 6397c7492..a020551f3 100644 --- a/libsolidity/codegen/ExpressionCompiler.cpp +++ b/libsolidity/codegen/ExpressionCompiler.cpp @@ -100,7 +100,7 @@ void ExpressionCompiler::appendStateVariableAccessor(VariableDeclaration const& if (_varDecl.immutable()) solAssert(paramTypes.empty(), ""); - m_context.adjustStackOffset(1 + CompilerUtils::sizeOnStack(paramTypes)); + m_context.adjustStackOffset(static_cast(1 + CompilerUtils::sizeOnStack(paramTypes))); if (!_varDecl.immutable()) { @@ -242,7 +242,7 @@ bool ExpressionCompiler::visit(Conditional const& _condition) acceptAndConvert(_condition.falseExpression(), *_condition.annotation().type); evmasm::AssemblyItem endTag = m_context.appendJumpToNew(); m_context << trueTag; - int offset = _condition.annotation().type->sizeOnStack(); + int offset = static_cast(_condition.annotation().type->sizeOnStack()); m_context.adjustStackOffset(-offset); acceptAndConvert(_condition.trueExpression(), *_condition.annotation().type); m_context << endTag; @@ -619,7 +619,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall) unsigned returnParametersSize = CompilerUtils::sizeOnStack(function.returnParameterTypes()); // callee adds return parameters, but removes arguments and return label - m_context.adjustStackOffset(returnParametersSize - parameterSize - 1); + m_context.adjustStackOffset(static_cast(returnParametersSize - parameterSize) - 1); break; } case FunctionType::Kind::BareCall: @@ -705,7 +705,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall) acceptAndConvert(*arguments.front(), *TypeProvider::uint256(), true); // Note that function is not the original function, but the ".gas" function. // Its values of gasSet and valueSet is equal to the original function's though. - unsigned stackDepth = (function.gasSet() ? 1 : 0) + (function.valueSet() ? 1 : 0); + unsigned stackDepth = (function.gasSet() ? 1u : 0u) + (function.valueSet() ? 1u : 0u); if (stackDepth > 0) m_context << swapInstruction(stackDepth); if (function.gasSet()) @@ -814,7 +814,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall) case FunctionType::Kind::Log3: case FunctionType::Kind::Log4: { - unsigned logNumber = int(function.kind()) - int(FunctionType::Kind::Log0); + unsigned logNumber = static_cast(function.kind()) - static_cast(FunctionType::Kind::Log0); for (unsigned arg = logNumber; arg > 0; --arg) acceptAndConvert(*arguments[arg], *function.parameterTypes()[arg], true); arguments.front()->accept(*this); @@ -1088,7 +1088,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall) { utils().revertWithStringData(*arguments.at(1)->annotation().type); // Here, the argument is consumed, but in the other branch, it is still there. - m_context.adjustStackOffset(arguments.at(1)->annotation().type->sizeOnStack()); + m_context.adjustStackOffset(static_cast(arguments.at(1)->annotation().type->sizeOnStack())); } else m_context.appendRevert(); @@ -1271,9 +1271,9 @@ bool ExpressionCompiler::visit(FunctionCallOptions const& _functionCallOptions) acceptAndConvert(*_functionCallOptions.options()[i], *requiredType); solAssert(!contains(presentOptions, newOption), ""); - size_t insertPos = presentOptions.end() - lower_bound(presentOptions.begin(), presentOptions.end(), newOption); + ptrdiff_t insertPos = presentOptions.end() - lower_bound(presentOptions.begin(), presentOptions.end(), newOption); - utils().moveIntoStack(insertPos, 1); + utils().moveIntoStack(static_cast(insertPos), 1); presentOptions.insert(presentOptions.end() - insertPos, newOption); } @@ -2190,7 +2190,7 @@ void ExpressionCompiler::appendExternalFunctionCall( // contract address unsigned selfSize = _functionType.bound() ? _functionType.selfType()->sizeOnStack() : 0; - unsigned gasValueSize = (_functionType.gasSet() ? 1 : 0) + (_functionType.valueSet() ? 1 : 0); + unsigned gasValueSize = (_functionType.gasSet() ? 1u : 0u) + (_functionType.valueSet() ? 1u : 0u); unsigned contractStackPos = m_context.currentToBaseStackOffset(1 + gasValueSize + selfSize + (_functionType.isBareCall() ? 0 : 1)); unsigned gasStackPos = m_context.currentToBaseStackOffset(gasValueSize); unsigned valueStackPos = m_context.currentToBaseStackOffset(1); @@ -2361,7 +2361,7 @@ void ExpressionCompiler::appendExternalFunctionCall( m_context << Instruction::CALL; unsigned remainsSize = - 2 + // contract address, input_memory_end + 2u + // contract address, input_memory_end (_functionType.valueSet() ? 1 : 0) + (_functionType.gasSet() ? 1 : 0) + (!_functionType.isBareCall() ? 1 : 0); diff --git a/libsolidity/codegen/ir/IRGeneratorForStatements.cpp b/libsolidity/codegen/ir/IRGeneratorForStatements.cpp index a62251ab1..beaff69ae 100644 --- a/libsolidity/codegen/ir/IRGeneratorForStatements.cpp +++ b/libsolidity/codegen/ir/IRGeneratorForStatements.cpp @@ -636,7 +636,7 @@ void IRGeneratorForStatements::endVisit(FunctionCall const& _functionCall) }); solAssert(it != callArgumentNames.cend(), ""); - arguments.push_back(callArguments[std::distance(callArgumentNames.begin(), it)]); + arguments.push_back(callArguments[static_cast(std::distance(callArgumentNames.begin(), it))]); } auto memberAccess = dynamic_cast(&_functionCall.expression()); @@ -1092,7 +1092,7 @@ void IRGeneratorForStatements::endVisit(FunctionCall const& _functionCall) case FunctionType::Kind::Log3: case FunctionType::Kind::Log4: { - unsigned logNumber = int(functionType->kind()) - int(FunctionType::Kind::Log0); + unsigned logNumber = static_cast(functionType->kind()) - static_cast(FunctionType::Kind::Log0); solAssert(arguments.size() == logNumber + 1, ""); ABIFunctions abi(m_context.evmVersion(), m_context.revertStrings(), m_context.functionCollector()); string indexedArgs; diff --git a/libsolidity/formal/CHC.cpp b/libsolidity/formal/CHC.cpp index f0ba6d0de..791a4f41d 100644 --- a/libsolidity/formal/CHC.cpp +++ b/libsolidity/formal/CHC.cpp @@ -104,7 +104,7 @@ void CHC::analyze(SourceUnit const& _source) for (auto const* assertion: assertions) { createErrorBlock(); - connectBlocks(target.value, error(), target.constraints && (target.errorId == assertion->id())); + connectBlocks(target.value, error(), target.constraints && (target.errorId == static_cast(assertion->id()))); auto [result, model] = query(error(), assertion->location()); // This should be fine but it's a bug in the old compiler (void)model; @@ -116,7 +116,7 @@ void CHC::analyze(SourceUnit const& _source) { solAssert(dynamic_cast(scope), ""); createErrorBlock(); - connectBlocks(target.value, error(), target.constraints && (target.errorId == scope->id())); + connectBlocks(target.value, error(), target.constraints && (target.errorId == static_cast(scope->id()))); auto [result, model] = query(error(), scope->location()); // This should be fine but it's a bug in the old compiler (void)model; @@ -533,7 +533,9 @@ void CHC::visitAssert(FunctionCall const& _funCall) connectBlocks( m_currentBlock, m_currentFunction->isConstructor() ? summary(*m_currentContract) : summary(*m_currentFunction), - currentPathConditions() && !m_context.expression(*args.front())->currentValue() && (m_error.currentValue() == _funCall.id()) + currentPathConditions() && !m_context.expression(*args.front())->currentValue() && ( + m_error.currentValue() == static_cast(_funCall.id()) + ) ); m_context.addAssertion(m_error.currentValue() == previousError); @@ -601,7 +603,7 @@ void CHC::makeArrayPopVerificationTarget(FunctionCall const& _arrayPop) connectBlocks( m_currentBlock, m_currentFunction->isConstructor() ? summary(*m_currentContract) : summary(*m_currentFunction), - currentPathConditions() && symbArray->length() <= 0 && m_error.currentValue() == _arrayPop.id() + currentPathConditions() && symbArray->length() <= 0 && m_error.currentValue() == static_cast(_arrayPop.id()) ); m_context.addAssertion(m_error.currentValue() == previousError); @@ -891,13 +893,13 @@ vector CHC::initialStateVariables() return stateVariablesAtIndex(0); } -vector CHC::stateVariablesAtIndex(int _index) +vector CHC::stateVariablesAtIndex(unsigned _index) { solAssert(m_currentContract, ""); return applyMap(m_stateVariables, [&](auto _var) { return valueAtIndex(*_var, _index); }); } -vector CHC::stateVariablesAtIndex(int _index, ContractDefinition const& _contract) +vector CHC::stateVariablesAtIndex(unsigned _index, ContractDefinition const& _contract) { return applyMap( stateVariablesIncludingInheritedAndPrivate(_contract), diff --git a/libsolidity/formal/CHC.h b/libsolidity/formal/CHC.h index b1235a188..b52ce6667 100644 --- a/libsolidity/formal/CHC.h +++ b/libsolidity/formal/CHC.h @@ -149,8 +149,8 @@ private: /// @returns the symbolic values of the state variables at the beginning /// of the current transaction. std::vector initialStateVariables(); - std::vector stateVariablesAtIndex(int _index); - std::vector stateVariablesAtIndex(int _index, ContractDefinition const& _contract); + std::vector stateVariablesAtIndex(unsigned _index); + std::vector stateVariablesAtIndex(unsigned _index, ContractDefinition const& _contract); /// @returns the current symbolic values of the current state variables. std::vector currentStateVariables(); diff --git a/libsolidity/formal/SMTEncoder.cpp b/libsolidity/formal/SMTEncoder.cpp index b9c43f2c5..82cd75578 100644 --- a/libsolidity/formal/SMTEncoder.cpp +++ b/libsolidity/formal/SMTEncoder.cpp @@ -154,15 +154,16 @@ void SMTEncoder::visitFunctionOrModifier() ++m_modifierDepthStack.back(); FunctionDefinition const& function = dynamic_cast(*m_callStack.back().first); - if (m_modifierDepthStack.back() == int(function.modifiers().size())) + if (m_modifierDepthStack.back() == static_cast(function.modifiers().size())) { if (function.isImplemented()) function.body().accept(*this); } else { - solAssert(m_modifierDepthStack.back() < int(function.modifiers().size()), ""); - ASTPointer const& modifierInvocation = function.modifiers()[m_modifierDepthStack.back()]; + solAssert(m_modifierDepthStack.back() < static_cast(function.modifiers().size()), ""); + ASTPointer const& modifierInvocation = + function.modifiers()[static_cast(m_modifierDepthStack.back())]; solAssert(modifierInvocation, ""); auto refDecl = modifierInvocation->name()->annotation().referencedDeclaration; if (dynamic_cast(refDecl)) @@ -1679,8 +1680,8 @@ void SMTEncoder::mergeVariables(set const& _variable for (auto const* decl: sortedVars) { solAssert(_indicesEndTrue.count(decl) && _indicesEndFalse.count(decl), ""); - int trueIndex = _indicesEndTrue.at(decl); - int falseIndex = _indicesEndFalse.at(decl); + auto trueIndex = static_cast(_indicesEndTrue.at(decl)); + auto falseIndex = static_cast(_indicesEndFalse.at(decl)); solAssert(trueIndex != falseIndex, ""); m_context.addAssertion(m_context.newValue(*decl) == smtutil::Expression::ite( _condition, @@ -1696,7 +1697,7 @@ smtutil::Expression SMTEncoder::currentValue(VariableDeclaration const& _decl) return m_context.variable(_decl)->currentValue(); } -smtutil::Expression SMTEncoder::valueAtIndex(VariableDeclaration const& _decl, int _index) +smtutil::Expression SMTEncoder::valueAtIndex(VariableDeclaration const& _decl, unsigned _index) { solAssert(m_context.knownVariable(_decl), ""); return m_context.variable(_decl)->valueAtIndex(_index); @@ -1819,7 +1820,7 @@ SMTEncoder::VariableIndices SMTEncoder::copyVariableIndices() void SMTEncoder::resetVariableIndices(VariableIndices const& _indices) { for (auto const& var: _indices) - m_context.variable(*var.first)->setIndex(var.second); + m_context.variable(*var.first)->setIndex(static_cast(var.second)); } void SMTEncoder::clearIndices(ContractDefinition const* _contract, FunctionDefinition const* _function) diff --git a/libsolidity/formal/SMTEncoder.h b/libsolidity/formal/SMTEncoder.h index 824d39b34..86ed21ef9 100644 --- a/libsolidity/formal/SMTEncoder.h +++ b/libsolidity/formal/SMTEncoder.h @@ -201,7 +201,7 @@ protected: smtutil::Expression currentValue(VariableDeclaration const& _decl); /// @returns an expression denoting the value of the variable declared in @a _decl /// at the given index. Does not ensure that this index exists. - smtutil::Expression valueAtIndex(VariableDeclaration const& _decl, int _index); + smtutil::Expression valueAtIndex(VariableDeclaration const& _decl, unsigned _index); /// Returns the expression corresponding to the AST node. /// If _targetType is not null apply conversion. /// Throws if the expression does not exist. diff --git a/libsolidity/formal/SymbolicVariables.cpp b/libsolidity/formal/SymbolicVariables.cpp index 002df6002..3f86b48d9 100644 --- a/libsolidity/formal/SymbolicVariables.cpp +++ b/libsolidity/formal/SymbolicVariables.cpp @@ -66,12 +66,12 @@ string SymbolicVariable::currentName() const return uniqueSymbol(m_ssa->index()); } -smtutil::Expression SymbolicVariable::valueAtIndex(int _index) const +smtutil::Expression SymbolicVariable::valueAtIndex(unsigned _index) const { return m_context.newVariable(uniqueSymbol(_index), m_sort); } -string SymbolicVariable::nameAtIndex(int _index) const +string SymbolicVariable::nameAtIndex(unsigned _index) const { return uniqueSymbol(_index); } @@ -170,12 +170,12 @@ smtutil::Expression SymbolicFunctionVariable::currentFunctionValue() const return m_declaration; } -smtutil::Expression SymbolicFunctionVariable::valueAtIndex(int _index) const +smtutil::Expression SymbolicFunctionVariable::valueAtIndex(unsigned _index) const { return m_abstract.valueAtIndex(_index); } -smtutil::Expression SymbolicFunctionVariable::functionValueAtIndex(int _index) const +smtutil::Expression SymbolicFunctionVariable::functionValueAtIndex(unsigned _index) const { return SymbolicVariable::valueAtIndex(_index); } @@ -304,7 +304,7 @@ smtutil::Expression SymbolicArrayVariable::currentValue(frontend::TypePointer co return m_pair.currentValue(); } -smtutil::Expression SymbolicArrayVariable::valueAtIndex(int _index) const +smtutil::Expression SymbolicArrayVariable::valueAtIndex(unsigned _index) const { return m_pair.valueAtIndex(_index); } diff --git a/libsolidity/formal/SymbolicVariables.h b/libsolidity/formal/SymbolicVariables.h index a7c0bd170..65dce43f0 100644 --- a/libsolidity/formal/SymbolicVariables.h +++ b/libsolidity/formal/SymbolicVariables.h @@ -54,8 +54,8 @@ public: virtual smtutil::Expression currentValue(frontend::TypePointer const& _targetType = TypePointer{}) const; std::string currentName() const; - virtual smtutil::Expression valueAtIndex(int _index) const; - virtual std::string nameAtIndex(int _index) const; + virtual smtutil::Expression valueAtIndex(unsigned _index) const; + virtual std::string nameAtIndex(unsigned _index) const; virtual smtutil::Expression resetIndex(); virtual smtutil::Expression setIndex(unsigned _index); virtual smtutil::Expression increaseIndex(); @@ -165,10 +165,10 @@ public: // Explicit request the function declaration. smtutil::Expression currentFunctionValue() const; - smtutil::Expression valueAtIndex(int _index) const override; + smtutil::Expression valueAtIndex(unsigned _index) const override; // Explicit request the function declaration. - smtutil::Expression functionValueAtIndex(int _index) const; + smtutil::Expression functionValueAtIndex(unsigned _index) const; smtutil::Expression resetIndex() override; smtutil::Expression setIndex(unsigned _index) override; @@ -251,7 +251,7 @@ public: SymbolicArrayVariable(SymbolicArrayVariable&&) = default; smtutil::Expression currentValue(frontend::TypePointer const& _targetType = TypePointer{}) const override; - smtutil::Expression valueAtIndex(int _index) const override; + smtutil::Expression valueAtIndex(unsigned _index) const override; smtutil::Expression resetIndex() override { SymbolicVariable::resetIndex(); return m_pair.resetIndex(); } smtutil::Expression setIndex(unsigned _index) override { SymbolicVariable::setIndex(_index); return m_pair.setIndex(_index); } smtutil::Expression increaseIndex() override { SymbolicVariable::increaseIndex(); return m_pair.increaseIndex(); } diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp index f662d361e..a8efdfb0b 100644 --- a/libsolidity/interface/CompilerStack.cpp +++ b/libsolidity/interface/CompilerStack.cpp @@ -982,7 +982,7 @@ string CompilerStack::applyRemapping(string const& _path, string const& _context bestMatchTarget = util::sanitizePath(redir.target); } string path = bestMatchTarget; - path.append(_path.begin() + longestPrefix, _path.end()); + path.append(_path.begin() + static_cast(longestPrefix), _path.end()); return path; } diff --git a/libsolidity/interface/GasEstimator.cpp b/libsolidity/interface/GasEstimator.cpp index 7282b1598..1a86f36ce 100644 --- a/libsolidity/interface/GasEstimator.cpp +++ b/libsolidity/interface/GasEstimator.cpp @@ -54,8 +54,8 @@ GasEstimator::ASTGasConsumptionSelfAccumulated GasEstimator::structuralEstimatio { solAssert(!!block.startState, ""); GasMeter meter(block.startState->copy(), m_evmVersion); - auto const end = _items.begin() + block.end; - for (auto iter = _items.begin() + block.begin; iter != end; ++iter) + auto const end = _items.begin() + static_cast(block.end); + for (auto iter = _items.begin() + static_cast(block.begin); iter != end; ++iter) particularCosts[iter->location()] += meter.estimateMax(*iter); } diff --git a/libsolidity/interface/StorageLayout.cpp b/libsolidity/interface/StorageLayout.cpp index 8e6915085..806652cfe 100644 --- a/libsolidity/interface/StorageLayout.cpp +++ b/libsolidity/interface/StorageLayout.cpp @@ -50,7 +50,7 @@ Json::Value StorageLayout::generate(VariableDeclaration const& _var, u256 const& TypePointer varType = _var.type(); varEntry["label"] = _var.name(); - varEntry["astId"] = int(_var.id()); + varEntry["astId"] = static_cast(_var.id()); varEntry["contract"] = m_contract->fullyQualifiedName(); varEntry["slot"] = _slot.str(); varEntry["offset"] = _offset; diff --git a/test/libsolidity/ABIEncoderTests.cpp b/test/libsolidity/ABIEncoderTests.cpp index b816de6fd..2e50fe743 100644 --- a/test/libsolidity/ABIEncoderTests.cpp +++ b/test/libsolidity/ABIEncoderTests.cpp @@ -606,7 +606,7 @@ BOOST_AUTO_TEST_CASE(bytesNN_arrays) BOTH_ENCODERS( for (size_t size = 1; size < 15; size++) { - for (size_t width: {1, 2, 4, 5, 7, 15, 16, 17, 31, 32}) + for (size_t width: {1u, 2u, 4u, 5u, 7u, 15u, 16u, 17u, 31u, 32u}) { string source = boost::algorithm::replace_all_copy(sourceCode, "SIZE", to_string(size)); source = boost::algorithm::replace_all_copy(source, "UINTWIDTH", to_string(width * 8)); @@ -651,7 +651,7 @@ BOOST_AUTO_TEST_CASE(bytesNN_arrays_dyn) BOTH_ENCODERS( for (size_t size = 0; size < 15; size++) { - for (size_t width: {1, 2, 4, 5, 7, 15, 16, 17, 31, 32}) + for (size_t width: {1u, 2u, 4u, 5u, 7u, 15u, 16u, 17u, 31u, 32u}) { string source = boost::algorithm::replace_all_copy(sourceCode, "SIZE", to_string(size)); source = boost::algorithm::replace_all_copy(source, "UINTWIDTH", to_string(width * 8)); diff --git a/test/libsolidity/SMTCheckerJSONTest.cpp b/test/libsolidity/SMTCheckerJSONTest.cpp index 484db13ff..396ecb280 100644 --- a/test/libsolidity/SMTCheckerJSONTest.cpp +++ b/test/libsolidity/SMTCheckerJSONTest.cpp @@ -116,21 +116,21 @@ TestCase::TestResult SMTCheckerJSONTest::run(ostream& _stream, string const& _li !location["end"].isInt() ) BOOST_THROW_EXCEPTION(runtime_error("Error must have a SourceLocation with start and end.")); - int start = location["start"].asInt(); - int end = location["end"].asInt(); + size_t start = location["start"].asUInt(); + size_t end = location["end"].asUInt(); std::string sourceName; if (location.isMember("source") && location["source"].isString()) sourceName = location["source"].asString(); - if (start >= static_cast(preamble.size())) + if (start >= preamble.size()) start -= preamble.size(); - if (end >= static_cast(preamble.size())) + if (end >= preamble.size()) end -= preamble.size(); m_errorList.emplace_back(SyntaxTestError{ error["type"].asString(), error["message"].asString(), sourceName, - start, - end + static_cast(start), + static_cast(end) }); } } diff --git a/test/libsolidity/SolidityExpressionCompiler.cpp b/test/libsolidity/SolidityExpressionCompiler.cpp index d40e64ebf..41c850b4d 100644 --- a/test/libsolidity/SolidityExpressionCompiler.cpp +++ b/test/libsolidity/SolidityExpressionCompiler.cpp @@ -143,8 +143,8 @@ bytes compileFirstExpression( ); context.resetVisitedNodes(contract); context.setMostDerivedContract(*contract); - unsigned parametersSize = _localVariables.size(); // assume they are all one slot on the stack - context.adjustStackOffset(parametersSize); + size_t parametersSize = _localVariables.size(); // assume they are all one slot on the stack + context.adjustStackOffset(static_cast(parametersSize)); for (vector const& variable: _localVariables) context.addVariable( dynamic_cast(resolveDeclaration(*sourceUnit, variable, resolver)), diff --git a/test/libsolidity/SolidityOptimizer.cpp b/test/libsolidity/SolidityOptimizer.cpp index fec67f0e6..4062b1928 100644 --- a/test/libsolidity/SolidityOptimizer.cpp +++ b/test/libsolidity/SolidityOptimizer.cpp @@ -491,7 +491,7 @@ BOOST_AUTO_TEST_CASE(constant_optimization_early_exit) #endif #endif #if __SANITIZE_ADDRESS__ - maxDuration = size_t(-1); + maxDuration = numeric_limits::max(); BOOST_TEST_MESSAGE("Disabled constant optimizer run time check for address sanitizer build."); #endif BOOST_CHECK_MESSAGE(duration <= maxDuration, "Compilation of constants took longer than 20 seconds."); diff --git a/test/libsolidity/SolidityParser.cpp b/test/libsolidity/SolidityParser.cpp index 12fbc3fce..364c0e2d5 100644 --- a/test/libsolidity/SolidityParser.cpp +++ b/test/libsolidity/SolidityParser.cpp @@ -675,7 +675,7 @@ BOOST_AUTO_TEST_CASE(inline_asm_end_location) bool visit(InlineAssembly const& _inlineAsm) override { auto loc = _inlineAsm.location(); - auto asmStr = loc.source->source().substr(loc.start, loc.end - loc.start); + auto asmStr = loc.source->source().substr(static_cast(loc.start), static_cast(loc.end - loc.start)); BOOST_CHECK_EQUAL(asmStr, "assembly { a := 0x12345678 }"); visited = true; diff --git a/test/libsolidity/SyntaxTest.cpp b/test/libsolidity/SyntaxTest.cpp index 55a77ed30..47411748e 100644 --- a/test/libsolidity/SyntaxTest.cpp +++ b/test/libsolidity/SyntaxTest.cpp @@ -98,9 +98,9 @@ void SyntaxTest::filterObtainedErrors() { // ignore the version & license pragma inserted by the testing tool when calculating locations. if (location->start >= static_cast(preamble.size())) - locationStart = location->start - (preamble.size()); + locationStart = location->start - static_cast(preamble.size()); if (location->end >= static_cast(preamble.size())) - locationEnd = location->end - (preamble.size()); + locationEnd = location->end - static_cast(preamble.size()); if (location->source) sourceName = location->source->name(); } diff --git a/test/libsolidity/util/BytesUtils.cpp b/test/libsolidity/util/BytesUtils.cpp index 72f7c7594..fd2cd2fcf 100644 --- a/test/libsolidity/util/BytesUtils.cpp +++ b/test/libsolidity/util/BytesUtils.cpp @@ -348,10 +348,10 @@ string BytesUtils::formatBytesRange( size_t BytesUtils::countRightPaddedZeros(bytes const& _bytes) { - return find_if( + return static_cast(find_if( _bytes.rbegin(), _bytes.rend(), [](uint8_t b) { return b != '\0'; } - ) - _bytes.rbegin(); + ) - _bytes.rbegin()); } diff --git a/test/libsolidity/util/TestFileParserTests.cpp b/test/libsolidity/util/TestFileParserTests.cpp index d24a80b95..4fb44d7cd 100644 --- a/test/libsolidity/util/TestFileParserTests.cpp +++ b/test/libsolidity/util/TestFileParserTests.cpp @@ -66,7 +66,7 @@ void testFunctionCall( ABI_CHECK(_call.expectations.rawBytes(), _expectations); BOOST_REQUIRE_EQUAL(_call.displayMode, _mode); BOOST_REQUIRE_EQUAL(_call.value.value, _value.value); - BOOST_REQUIRE_EQUAL(size_t(_call.value.unit), size_t(_value.unit)); + BOOST_REQUIRE_EQUAL(static_cast(_call.value.unit), static_cast(_value.unit)); BOOST_REQUIRE_EQUAL(_call.arguments.comment, _argumentComment); BOOST_REQUIRE_EQUAL(_call.expectations.comment, _expectationComment);