mirror of
				https://github.com/ethereum/solidity
				synced 2023-10-03 13:03:40 +00:00 
			
		
		
		
	Merge pull request #9082 from ethereum/conversionWarnings
Adding `-Wsign-conversion` flag and fixing errors
This commit is contained in:
		
						commit
						b3566ad0d5
					
				| @ -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") | ||||
|  | ||||
| @ -245,14 +245,14 @@ unsigned SemVerMatchExpressionParser::parseVersionPart() | ||||
| 		return 0; | ||||
| 	else if ('1' <= c && c <= '9') | ||||
| 	{ | ||||
| 		unsigned v(c - '0'); | ||||
| 		auto v = static_cast<unsigned>(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<unsigned>(c - '0') < v * 10) | ||||
| 				throw SemVerError(); | ||||
| 			v = v * 10 + unsigned(c - '0'); | ||||
| 			v = v * 10 + static_cast<unsigned>(c - '0'); | ||||
| 			nextChar(); | ||||
| 		} | ||||
| 		return v; | ||||
|  | ||||
| @ -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( | ||||
|  | ||||
| @ -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.
 | ||||
|  | ||||
| @ -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") | ||||
|  | ||||
| @ -646,7 +646,7 @@ bool ContractCompiler::visit(FunctionDefinition const& _function) | ||||
| 		} | ||||
| 		else | ||||
| 		{ | ||||
| 			m_context << swapInstruction(stackLayout.size() - static_cast<size_t>(stackLayout.back()) - 1); | ||||
| 			m_context << swapInstruction(stackLayout.size() - static_cast<unsigned>(stackLayout.back()) - 1u); | ||||
| 			swap(stackLayout[static_cast<size_t>(stackLayout.back())], stackLayout.back()); | ||||
| 		} | ||||
| 	for (size_t i = 0; i < stackLayout.size(); ++i) | ||||
|  | ||||
| @ -950,13 +950,13 @@ vector<smtutil::Expression> CHC::initialStateVariables(ContractDefinition const& | ||||
| 	return stateVariablesAtIndex(0, _contract); | ||||
| } | ||||
| 
 | ||||
| vector<smtutil::Expression> CHC::stateVariablesAtIndex(int _index) | ||||
| vector<smtutil::Expression> CHC::stateVariablesAtIndex(unsigned _index) | ||||
| { | ||||
| 	solAssert(m_currentContract, ""); | ||||
| 	return stateVariablesAtIndex(_index, *m_currentContract); | ||||
| } | ||||
| 
 | ||||
| vector<smtutil::Expression> CHC::stateVariablesAtIndex(int _index, ContractDefinition const& _contract) | ||||
| vector<smtutil::Expression> CHC::stateVariablesAtIndex(unsigned _index, ContractDefinition const& _contract) | ||||
| { | ||||
| 	return applyMap( | ||||
| 		stateVariablesIncludingInheritedAndPrivate(_contract), | ||||
|  | ||||
| @ -154,8 +154,8 @@ private: | ||||
| 	/// of the current transaction.
 | ||||
| 	std::vector<smtutil::Expression> initialStateVariables(); | ||||
| 	std::vector<smtutil::Expression> initialStateVariables(ContractDefinition const& _contract); | ||||
| 	std::vector<smtutil::Expression> stateVariablesAtIndex(int _index); | ||||
| 	std::vector<smtutil::Expression> stateVariablesAtIndex(int _index, ContractDefinition const& _contract); | ||||
| 	std::vector<smtutil::Expression> stateVariablesAtIndex(unsigned _index); | ||||
| 	std::vector<smtutil::Expression> stateVariablesAtIndex(unsigned _index, ContractDefinition const& _contract); | ||||
| 	/// @returns the current symbolic values of the current state variables.
 | ||||
| 	std::vector<smtutil::Expression> currentStateVariables(); | ||||
| 	std::vector<smtutil::Expression> currentStateVariables(ContractDefinition const& _contract); | ||||
|  | ||||
| @ -1253,7 +1253,7 @@ pair<smtutil::Expression, smtutil::Expression> 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<size_t >::max(); | ||||
| 		smtutil::Expression wrap = smtutil::Expression::ite(maxLeft && minusOneRight, smt::minValue(*intType), valueUnbounded); | ||||
| 		return {wrap, valueUnbounded}; | ||||
| 	} | ||||
|  | ||||
| @ -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<int>(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<Scope::Function>(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<int>(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<int>(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<size_t>(stackLayout.back()) - 1)); | ||||
| 					m_assembly.appendInstruction(evmasm::swapInstruction(static_cast<unsigned>(stackLayout.size()) - static_cast<unsigned>(stackLayout.back()) - 1u)); | ||||
| 					swap(stackLayout[static_cast<size_t>(stackLayout.back())], stackLayout.back()); | ||||
| 				} | ||||
| 			for (size_t i = 0; i < stackLayout.size(); ++i) | ||||
|  | ||||
| @ -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 | ||||
|  | ||||
| @ -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<size_t>(_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<size_t>(_x.varnum()) % m_currentGlobalVars.size()]; | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
|  | ||||
| @ -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<streamsize>(sol_source.size())); | ||||
| 	} | ||||
| 
 | ||||
| 	if (char const* dump_path = getenv("SOL_DEBUG_FILE")) | ||||
|  | ||||
| @ -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<streamsize>(yul_source.size())); | ||||
| 	} | ||||
| 
 | ||||
| 	if (yul_source.size() > 1200) | ||||
|  | ||||
| @ -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<streamsize>(yul_source.size())); | ||||
| 	} | ||||
| 
 | ||||
| 	YulStringRepository::reset(); | ||||
|  | ||||
| @ -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.
 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user