diff --git a/cmake/EthCompilerSettings.cmake b/cmake/EthCompilerSettings.cmake index 1f7600d9b..3bcdad47b 100644 --- a/cmake/EthCompilerSettings.cmake +++ b/cmake/EthCompilerSettings.cmake @@ -50,6 +50,7 @@ if (("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") OR ("${CMAKE_CXX_COMPILER_ID}" MA add_compile_options(-pedantic) add_compile_options(-Wno-unknown-pragmas) add_compile_options(-Wimplicit-fallthrough) + add_compile_options(-Wsign-conversion) # Configuration-specific compiler settings. set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g3 -DETH_DEBUG") diff --git a/liblangutil/SemVerHandler.cpp b/liblangutil/SemVerHandler.cpp index a626c5aa7..d997cb073 100644 --- a/liblangutil/SemVerHandler.cpp +++ b/liblangutil/SemVerHandler.cpp @@ -245,14 +245,14 @@ unsigned SemVerMatchExpressionParser::parseVersionPart() return 0; else if ('1' <= c && c <= '9') { - unsigned v(c - '0'); + auto v = static_cast(c - '0'); // If we skip to the next token, the current number is terminated. while (m_pos == startPos && '0' <= currentChar() && currentChar() <= '9') { c = currentChar(); - if (v * 10 < v || v * 10 + unsigned(c - '0') < v * 10) + if (v * 10 < v || v * 10 + static_cast(c - '0') < v * 10) throw SemVerError(); - v = v * 10 + unsigned(c - '0'); + v = v * 10 + static_cast(c - '0'); nextChar(); } return v; diff --git a/libsmtutil/CVC4Interface.cpp b/libsmtutil/CVC4Interface.cpp index 7735d5a16..f58e46801 100644 --- a/libsmtutil/CVC4Interface.cpp +++ b/libsmtutil/CVC4Interface.cpp @@ -191,7 +191,7 @@ CVC4::Expr CVC4Interface::toCVC4Expr(Expression const& _expr) return m_context.mkExpr(CVC4::kind::BITVECTOR_AND, arguments[0], arguments[1]); else if (n == "int2bv") { - size_t size = std::stoi(_expr.arguments[1].name); + size_t size = std::stoul(_expr.arguments[1].name); auto i2bvOp = m_context.mkConst(CVC4::IntToBitVector(size)); // CVC4 treats all BVs as unsigned, so we need to manually apply 2's complement if needed. return m_context.mkExpr( diff --git a/libsmtutil/SMTLib2Interface.cpp b/libsmtutil/SMTLib2Interface.cpp index ce1efb5f6..1f87b9b72 100644 --- a/libsmtutil/SMTLib2Interface.cpp +++ b/libsmtutil/SMTLib2Interface.cpp @@ -139,7 +139,7 @@ string SMTLib2Interface::toSExpr(Expression const& _expr) std::string sexpr = "("; if (_expr.name == "int2bv") { - size_t size = std::stoi(_expr.arguments[1].name); + size_t size = std::stoul(_expr.arguments[1].name); auto arg = toSExpr(_expr.arguments.front()); auto int2bv = "(_ int2bv " + to_string(size) + ")"; // Some solvers treat all BVs as unsigned, so we need to manually apply 2's complement if needed. diff --git a/libsmtutil/Z3Interface.cpp b/libsmtutil/Z3Interface.cpp index a71d008ab..c2309ad4f 100644 --- a/libsmtutil/Z3Interface.cpp +++ b/libsmtutil/Z3Interface.cpp @@ -184,7 +184,7 @@ z3::expr Z3Interface::toZ3Expr(Expression const& _expr) return arguments[0] & arguments[1]; else if (n == "int2bv") { - size_t size = std::stoi(_expr.arguments[1].name); + size_t size = std::stoul(_expr.arguments[1].name); return z3::int2bv(size, arguments[0]); } else if (n == "bv2int") diff --git a/libsolidity/codegen/ContractCompiler.cpp b/libsolidity/codegen/ContractCompiler.cpp index 3d1b41e41..ad9c97474 100644 --- a/libsolidity/codegen/ContractCompiler.cpp +++ b/libsolidity/codegen/ContractCompiler.cpp @@ -646,7 +646,7 @@ bool ContractCompiler::visit(FunctionDefinition const& _function) } else { - m_context << swapInstruction(stackLayout.size() - static_cast(stackLayout.back()) - 1); + m_context << swapInstruction(stackLayout.size() - static_cast(stackLayout.back()) - 1u); swap(stackLayout[static_cast(stackLayout.back())], stackLayout.back()); } for (size_t i = 0; i < stackLayout.size(); ++i) diff --git a/libsolidity/formal/CHC.cpp b/libsolidity/formal/CHC.cpp index 336dfaa37..5dd8c958c 100644 --- a/libsolidity/formal/CHC.cpp +++ b/libsolidity/formal/CHC.cpp @@ -950,13 +950,13 @@ vector CHC::initialStateVariables(ContractDefinition const& return stateVariablesAtIndex(0, _contract); } -vector CHC::stateVariablesAtIndex(int _index) +vector CHC::stateVariablesAtIndex(unsigned _index) { solAssert(m_currentContract, ""); return stateVariablesAtIndex(_index, *m_currentContract); } -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 07af4c76b..5e518a130 100644 --- a/libsolidity/formal/CHC.h +++ b/libsolidity/formal/CHC.h @@ -154,8 +154,8 @@ private: /// of the current transaction. std::vector initialStateVariables(); std::vector initialStateVariables(ContractDefinition const& _contract); - 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(); std::vector currentStateVariables(ContractDefinition const& _contract); diff --git a/libsolidity/formal/SMTEncoder.cpp b/libsolidity/formal/SMTEncoder.cpp index bd2a9a754..eea0b24e5 100644 --- a/libsolidity/formal/SMTEncoder.cpp +++ b/libsolidity/formal/SMTEncoder.cpp @@ -1253,7 +1253,7 @@ pair SMTEncoder::arithmeticOperation( // - RHS is -1 // the result is then -(type.min), which wraps back to type.min smtutil::Expression maxLeft = _left == smt::minValue(*intType); - smtutil::Expression minusOneRight = _right == -1; + smtutil::Expression minusOneRight = _right == numeric_limits::max(); smtutil::Expression wrap = smtutil::Expression::ite(maxLeft && minusOneRight, smt::minValue(*intType), valueUnbounded); return {wrap, valueUnbounded}; } diff --git a/libyul/backends/evm/EVMCodeTransform.cpp b/libyul/backends/evm/EVMCodeTransform.cpp index 9182bb393..6b0f06e01 100644 --- a/libyul/backends/evm/EVMCodeTransform.cpp +++ b/libyul/backends/evm/EVMCodeTransform.cpp @@ -165,7 +165,7 @@ void CodeTransform::deleteVariable(Scope::Variable const& _var) { yulAssert(m_allowStackOpt, ""); yulAssert(m_context->variableStackHeights.count(&_var) > 0, ""); - m_unusedStackSlots.insert(m_context->variableStackHeights[&_var]); + m_unusedStackSlots.insert(static_cast(m_context->variableStackHeights[&_var])); m_context->variableStackHeights.erase(&_var); m_context->variableReferences.erase(&_var); m_variablesScheduledForDeletion.erase(&_var); @@ -402,7 +402,7 @@ void CodeTransform::operator()(FunctionDefinition const& _function) yulAssert(m_scope->identifiers.count(_function.name), ""); Scope::Function& function = std::get(m_scope->identifiers.at(_function.name)); - int height = m_evm15 ? 0 : 1; + size_t height = m_evm15 ? 0 : 1; yulAssert(m_info.scopes.at(&_function.body), ""); Scope* varScope = m_info.scopes.at(m_info.virtualBlocks.at(&_function).get()).get(); yulAssert(varScope, ""); @@ -420,7 +420,7 @@ void CodeTransform::operator()(FunctionDefinition const& _function) else m_assembly.appendLabel(functionEntryID(_function.name, function)); - m_assembly.setStackHeight(height); + m_assembly.setStackHeight(static_cast(height)); for (auto const& v: _function.returnVariables) { @@ -457,7 +457,7 @@ void CodeTransform::operator()(FunctionDefinition const& _function) StackTooDeepError error(_error); if (error.functionName.empty()) error.functionName = _function.name; - stackError(std::move(error), height); + stackError(std::move(error), static_cast(height)); } m_assembly.appendLabel(m_context->functionExitPoints.top().label); @@ -502,7 +502,7 @@ void CodeTransform::operator()(FunctionDefinition const& _function) } else { - m_assembly.appendInstruction(evmasm::swapInstruction(stackLayout.size() - static_cast(stackLayout.back()) - 1)); + m_assembly.appendInstruction(evmasm::swapInstruction(static_cast(stackLayout.size()) - static_cast(stackLayout.back()) - 1u)); swap(stackLayout[static_cast(stackLayout.back())], stackLayout.back()); } for (size_t i = 0; i < stackLayout.size(); ++i) diff --git a/test/tools/ossfuzz/CMakeLists.txt b/test/tools/ossfuzz/CMakeLists.txt index 8a33f1f7c..419b2021e 100644 --- a/test/tools/ossfuzz/CMakeLists.txt +++ b/test/tools/ossfuzz/CMakeLists.txt @@ -8,6 +8,7 @@ add_dependencies(ossfuzz strictasm_assembly_ossfuzz ) + if (OSSFUZZ) add_custom_target(ossfuzz_proto) add_dependencies(ossfuzz_proto @@ -54,6 +55,7 @@ if (OSSFUZZ) protobuf.a ) set_target_properties(yul_proto_ossfuzz PROPERTIES LINK_FLAGS ${LIB_FUZZING_ENGINE}) + target_compile_options(yul_proto_ossfuzz PUBLIC ${COMPILE_OPTIONS} -Wno-sign-conversion) add_executable(yul_proto_diff_ossfuzz yulProto_diff_ossfuzz.cpp yulFuzzerCommon.cpp protoToYul.cpp yulProto.pb.cc) target_include_directories(yul_proto_diff_ossfuzz PRIVATE /usr/include/libprotobuf-mutator) @@ -64,6 +66,7 @@ if (OSSFUZZ) protobuf.a ) set_target_properties(yul_proto_diff_ossfuzz PROPERTIES LINK_FLAGS ${LIB_FUZZING_ENGINE}) + target_compile_options(yul_proto_diff_ossfuzz PUBLIC ${COMPILE_OPTIONS} -Wno-sign-conversion) add_executable(yul_proto_diff_custom_mutate_ossfuzz yulProto_diff_ossfuzz.cpp @@ -99,6 +102,7 @@ if (OSSFUZZ) protobuf.a ) set_target_properties(abiv2_proto_ossfuzz PROPERTIES LINK_FLAGS ${LIB_FUZZING_ENGINE}) + target_compile_options(abiv2_proto_ossfuzz PUBLIC ${COMPILE_OPTIONS} -Wno-sign-conversion) add_executable(sol_proto_ossfuzz solProtoFuzzer.cpp @@ -118,6 +122,7 @@ if (OSSFUZZ) protobuf.a ) set_target_properties(sol_proto_ossfuzz PROPERTIES LINK_FLAGS ${LIB_FUZZING_ENGINE}) + target_compile_options(sol_proto_ossfuzz PUBLIC ${COMPILE_OPTIONS} -Wno-sign-conversion) else() add_library(solc_opt_ossfuzz solc_opt_ossfuzz.cpp diff --git a/test/tools/ossfuzz/protoToYul.cpp b/test/tools/ossfuzz/protoToYul.cpp index 73462356b..5d19d470c 100644 --- a/test/tools/ossfuzz/protoToYul.cpp +++ b/test/tools/ossfuzz/protoToYul.cpp @@ -192,13 +192,13 @@ void ProtoConverter::visit(VarRef const& _x) { // Ensure that there is at least one variable declaration to reference in function scope. yulAssert(m_currentFuncVars.size() > 0, "Proto fuzzer: No variables to reference."); - m_output << *m_currentFuncVars[_x.varnum() % m_currentFuncVars.size()]; + m_output << *m_currentFuncVars[static_cast(_x.varnum()) % m_currentFuncVars.size()]; } else { // Ensure that there is at least one variable declaration to reference in nested scopes. yulAssert(m_currentGlobalVars.size() > 0, "Proto fuzzer: No global variables to reference."); - m_output << *m_currentGlobalVars[_x.varnum() % m_currentGlobalVars.size()]; + m_output << *m_currentGlobalVars[static_cast(_x.varnum()) % m_currentGlobalVars.size()]; } } diff --git a/test/tools/ossfuzz/solProtoFuzzer.cpp b/test/tools/ossfuzz/solProtoFuzzer.cpp index 80facb3e1..663a94d36 100644 --- a/test/tools/ossfuzz/solProtoFuzzer.cpp +++ b/test/tools/ossfuzz/solProtoFuzzer.cpp @@ -202,7 +202,7 @@ DEFINE_PROTO_FUZZER(Program const& _input) // With libFuzzer binary run this to generate a YUL source file x.yul: // PROTO_FUZZER_DUMP_PATH=x.yul ./a.out proto-input ofstream of(dump_path); - of.write(sol_source.data(), sol_source.size()); + of.write(sol_source.data(), static_cast(sol_source.size())); } if (char const* dump_path = getenv("SOL_DEBUG_FILE")) diff --git a/test/tools/ossfuzz/yulProtoFuzzer.cpp b/test/tools/ossfuzz/yulProtoFuzzer.cpp index b78f6fc5c..cc0205d16 100644 --- a/test/tools/ossfuzz/yulProtoFuzzer.cpp +++ b/test/tools/ossfuzz/yulProtoFuzzer.cpp @@ -43,7 +43,7 @@ DEFINE_PROTO_FUZZER(Program const& _input) // With libFuzzer binary run this to generate a YUL source file x.yul: // PROTO_FUZZER_DUMP_PATH=x.yul ./a.out proto-input ofstream of(dump_path); - of.write(yul_source.data(), yul_source.size()); + of.write(yul_source.data(), static_cast(yul_source.size())); } if (yul_source.size() > 1200) diff --git a/test/tools/ossfuzz/yulProto_diff_ossfuzz.cpp b/test/tools/ossfuzz/yulProto_diff_ossfuzz.cpp index fd0f2e0a5..e5e6b203f 100644 --- a/test/tools/ossfuzz/yulProto_diff_ossfuzz.cpp +++ b/test/tools/ossfuzz/yulProto_diff_ossfuzz.cpp @@ -64,7 +64,7 @@ DEFINE_PROTO_FUZZER(Program const& _input) // With libFuzzer binary run this to generate a YUL source file x.yul: // PROTO_FUZZER_DUMP_PATH=x.yul ./a.out proto-input ofstream of(dump_path); - of.write(yul_source.data(), yul_source.size()); + of.write(yul_source.data(), static_cast(yul_source.size())); } YulStringRepository::reset(); diff --git a/test/yulPhaser/Mutations.cpp b/test/yulPhaser/Mutations.cpp index aae16cced..2d6b65c88 100644 --- a/test/yulPhaser/Mutations.cpp +++ b/test/yulPhaser/Mutations.cpp @@ -179,8 +179,8 @@ BOOST_AUTO_TEST_CASE(alternativeMutations_should_choose_between_mutations_with_g for (size_t i = 0; i < 10; ++i) { Chromosome mutatedChromosome = mutation(chromosome); - cCount += (mutatedChromosome == Chromosome("c") ? 1 : 0); - fCount += (mutatedChromosome == Chromosome("f") ? 1 : 0); + cCount += (mutatedChromosome == Chromosome("c") ? 1u : 0u); + fCount += (mutatedChromosome == Chromosome("f") ? 1u : 0u); } // This particular seed results in 7 "c"s out of 10 which looks plausible given the 80% chance.