Enable more C++ compiler warnings

This commit is contained in:
Alex Beregszaszi 2020-12-08 20:06:10 +00:00
parent 90c693be09
commit bd641a5206
27 changed files with 96 additions and 26 deletions

View File

@ -48,6 +48,7 @@ if (("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") OR ("${CMAKE_CXX_COMPILER_ID}" MA
add_compile_options(-Wextra) add_compile_options(-Wextra)
add_compile_options(-Werror) add_compile_options(-Werror)
add_compile_options(-pedantic) add_compile_options(-pedantic)
add_compile_options(-Wmissing-declarations)
add_compile_options(-Wno-unknown-pragmas) add_compile_options(-Wno-unknown-pragmas)
add_compile_options(-Wimplicit-fallthrough) add_compile_options(-Wimplicit-fallthrough)
add_compile_options(-Wsign-conversion) add_compile_options(-Wsign-conversion)
@ -56,6 +57,14 @@ if (("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") OR ("${CMAKE_CXX_COMPILER_ID}" MA
eth_add_cxx_compiler_flag_if_supported( eth_add_cxx_compiler_flag_if_supported(
$<$<COMPILE_LANGUAGE:CXX>:-Wextra-semi> $<$<COMPILE_LANGUAGE:CXX>:-Wextra-semi>
) )
eth_add_cxx_compiler_flag_if_supported(-Wfinal-dtor-non-final-class)
eth_add_cxx_compiler_flag_if_supported(-Wnewline-eof)
eth_add_cxx_compiler_flag_if_supported(-Wsuggest-destructor-override)
eth_add_cxx_compiler_flag_if_supported(-Wunreachable-code-break)
eth_add_cxx_compiler_flag_if_supported(-Wduplicated-cond)
eth_add_cxx_compiler_flag_if_supported(-Wduplicate-enum)
eth_add_cxx_compiler_flag_if_supported(-Wlogical-op)
eth_add_cxx_compiler_flag_if_supported(-Wno-unknown-attributes)
# Configuration-specific compiler settings. # Configuration-specific compiler settings.
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g3 -DETH_DEBUG") set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g3 -DETH_DEBUG")

View File

@ -126,6 +126,8 @@ int precedence(Token tok)
} }
#undef T #undef T
namespace
{
int parseSize(string::const_iterator _begin, string::const_iterator _end) int parseSize(string::const_iterator _begin, string::const_iterator _end)
{ {
try try
@ -138,6 +140,7 @@ int parseSize(string::const_iterator _begin, string::const_iterator _end)
return -1; return -1;
} }
} }
}
static Token keywordByName(string const& _name) static Token keywordByName(string const& _name)
{ {

View File

@ -34,6 +34,8 @@ using namespace std;
namespace solidity::frontend namespace solidity::frontend
{ {
namespace
{
/// Magic variables get negative ids for easy differentiation /// Magic variables get negative ids for easy differentiation
int magicVariableToID(std::string const& _name) int magicVariableToID(std::string const& _name)
{ {
@ -113,6 +115,8 @@ inline vector<shared_ptr<MagicVariableDeclaration const>> constructMagicVariable
}; };
} }
}
GlobalContext::GlobalContext(): m_magicVariables{constructMagicVariables()} GlobalContext::GlobalContext(): m_magicVariables{constructMagicVariables()}
{ {
} }

View File

@ -399,4 +399,4 @@ smtutil::Expression SymbolicStructVariable::assignAllMembers(vector<smtutil::Exp
m_context.addAssertion(_memberValues[i] == member(structMembers[i]->name())); m_context.addAssertion(_memberValues[i] == member(structMembers[i]->name()));
return currentValue(); return currentValue();
} }

View File

@ -76,8 +76,6 @@ bool isWellFormed(unsigned char byte1, unsigned char byte2)
return false; return false;
} }
}
bool validateUTF8(unsigned char const* _input, size_t _length, size_t& _invalidPosition) bool validateUTF8(unsigned char const* _input, size_t _length, size_t& _invalidPosition)
{ {
bool valid = true; bool valid = true;
@ -134,6 +132,8 @@ bool validateUTF8(unsigned char const* _input, size_t _length, size_t& _invalidP
return false; return false;
} }
}
bool validateUTF8(std::string const& _input, size_t& _invalidPosition) bool validateUTF8(std::string const& _input, size_t& _invalidPosition)
{ {
return validateUTF8(reinterpret_cast<unsigned char const*>(_input.c_str()), _input.length(), _invalidPosition); return validateUTF8(reinterpret_cast<unsigned char const*>(_input.c_str()), _input.length(), _invalidPosition);

View File

@ -36,4 +36,4 @@ void FunctionCallFinder::operator()(FunctionCall& _functionCall)
ASTModifier::operator()(_functionCall); ASTModifier::operator()(_functionCall);
if (_functionCall.functionName.name == m_functionName) if (_functionCall.functionName.name == m_functionName)
m_calls.emplace_back(&_functionCall); m_calls.emplace_back(&_functionCall);
} }

View File

@ -129,4 +129,4 @@ private:
NameDispenser& m_nameDispenser; NameDispenser& m_nameDispenser;
}; };
} }

View File

@ -92,6 +92,9 @@ namespace solidity::frontend
bool g_hasOutput = false; bool g_hasOutput = false;
namespace
{
std::ostream& sout() std::ostream& sout()
{ {
g_hasOutput = true; g_hasOutput = true;
@ -105,6 +108,8 @@ std::ostream& serr(bool _used = true)
return cerr; return cerr;
} }
}
#define cout #define cout
#define cerr #define cerr
@ -329,6 +334,9 @@ static bool needsHumanTargetedStdout(po::variables_map const& _args)
return false; return false;
} }
namespace
{
bool checkMutuallyExclusive(boost::program_options::variables_map const& args, std::string const& _optionA, std::string const& _optionB) bool checkMutuallyExclusive(boost::program_options::variables_map const& args, std::string const& _optionA, std::string const& _optionB)
{ {
if (args.count(_optionA) && args.count(_optionB)) if (args.count(_optionA) && args.count(_optionB))
@ -340,6 +348,8 @@ bool checkMutuallyExclusive(boost::program_options::variables_map const& args, s
return true; return true;
} }
}
void CommandLineInterface::handleBinary(string const& _contract) void CommandLineInterface::handleBinary(string const& _contract)
{ {
if (m_args.count(g_argBinary)) if (m_args.count(g_argBinary))

View File

@ -30,6 +30,9 @@ namespace po = boost::program_options;
namespace solidity::test namespace solidity::test
{ {
namespace
{
/// If non-empty returns the value of the env. variable ETH_TEST_PATH, otherwise /// If non-empty returns the value of the env. variable ETH_TEST_PATH, otherwise
/// it tries to find a path that contains the directories "libsolidity/syntaxTests" /// it tries to find a path that contains the directories "libsolidity/syntaxTests"
/// and returns it if found. /// and returns it if found.
@ -84,6 +87,8 @@ std::string envOrDefaultPath(std::string const& env_name, std::string const& lib
return {}; return {};
} }
}
CommonOptions::CommonOptions(std::string _caption): CommonOptions::CommonOptions(std::string _caption):
options(_caption, options(_caption,
po::options_description::m_default_line_length, po::options_description::m_default_line_length,

View File

@ -148,6 +148,10 @@ void initializeOptions()
} }
} }
// TODO: Prototype -- why isn't this declared in the boost headers?
// TODO: replace this with a (global) fixture.
test_suite* init_unit_test_suite( int /*argc*/, char* /*argv*/[] );
test_suite* init_unit_test_suite( int /*argc*/, char* /*argv*/[] ) test_suite* init_unit_test_suite( int /*argc*/, char* /*argv*/[] )
{ {
master_test_suite_t& master = framework::master_test_suite(); master_test_suite_t& master = framework::master_test_suite();

View File

@ -19,4 +19,4 @@ target_sources(evmc INTERFACE
${PROJECT_SOURCE_DIR}/test/evmc/utils.h ${PROJECT_SOURCE_DIR}/test/evmc/utils.h
) )
target_include_directories(evmc INTERFACE ${PROJECT_SOURCE_DIR}/test/) target_include_directories(evmc INTERFACE ${PROJECT_SOURCE_DIR}/test/)
target_link_libraries(evmc INTERFACE evmc_loader) target_link_libraries(evmc INTERFACE evmc_loader)

View File

@ -38,6 +38,9 @@ namespace solidity::frontend::test
BOOST_AUTO_TEST_SUITE(SemVerMatcher) BOOST_AUTO_TEST_SUITE(SemVerMatcher)
namespace
{
SemVerMatchExpression parseExpression(string const& _input) SemVerMatchExpression parseExpression(string const& _input)
{ {
Scanner scanner{CharStream(_input, "")}; Scanner scanner{CharStream(_input, "")};
@ -62,6 +65,8 @@ SemVerMatchExpression parseExpression(string const& _input)
return expression; return expression;
} }
}
BOOST_AUTO_TEST_CASE(positive_range) BOOST_AUTO_TEST_CASE(positive_range)
{ {
// Positive range tests // Positive range tests

View File

@ -39,6 +39,9 @@ namespace solidity::frontend::test
using fmt = ExecutionFramework; using fmt = ExecutionFramework;
using Mode = FunctionCall::DisplayMode; using Mode = FunctionCall::DisplayMode;
namespace
{
vector<FunctionCall> parse(string const& _source) vector<FunctionCall> parse(string const& _source)
{ {
istringstream stream{_source, ios_base::out}; istringstream stream{_source, ios_base::out};
@ -86,6 +89,8 @@ void testFunctionCall(
BOOST_REQUIRE_EQUAL(_call.kind == FunctionCall::Kind::Library, _isLibrary); BOOST_REQUIRE_EQUAL(_call.kind == FunctionCall::Kind::Library, _isLibrary);
} }
}
BOOST_AUTO_TEST_SUITE(TestFileParserTest) BOOST_AUTO_TEST_SUITE(TestFileParserTest)
BOOST_AUTO_TEST_CASE(smoke_test) BOOST_AUTO_TEST_CASE(smoke_test)

View File

@ -34,6 +34,9 @@ namespace solidity::util::test
BOOST_AUTO_TEST_SUITE(SwarmHash, *boost::unit_test::label("nooptions")) BOOST_AUTO_TEST_SUITE(SwarmHash, *boost::unit_test::label("nooptions"))
namespace
{
string bzzr0HashHex(string const& _input) string bzzr0HashHex(string const& _input)
{ {
return toHex(bzzr0Hash(_input).asBytes()); return toHex(bzzr0Hash(_input).asBytes());
@ -52,6 +55,8 @@ bytes sequence(size_t _length)
return data; return data;
} }
}
BOOST_AUTO_TEST_CASE(test_zeros) BOOST_AUTO_TEST_CASE(test_zeros)
{ {
BOOST_CHECK_EQUAL(bzzr0HashHex(string()), string("011b4d03dd8c01f1049143cf9c4c817e4b167f1d1b83e5c6f0f10d89ba1e7bce")); BOOST_CHECK_EQUAL(bzzr0HashHex(string()), string("011b4d03dd8c01f1049143cf9c4c817e4b167f1d1b83e5c6f0f10d89ba1e7bce"));

View File

@ -35,6 +35,9 @@ namespace po = boost::program_options;
namespace solidity::test namespace solidity::test
{ {
namespace
{
auto const description = R"(isoltest, tool for interactively managing test contracts. auto const description = R"(isoltest, tool for interactively managing test contracts.
Usage: isoltest [Options] Usage: isoltest [Options]
Interactively validates test contracts. Interactively validates test contracts.
@ -51,6 +54,8 @@ std::string editorPath()
return std::string{}; return std::string{};
} }
}
IsolTestOptions::IsolTestOptions(std::string* _editor): IsolTestOptions::IsolTestOptions(std::string* _editor):
CommonOptions(description) CommonOptions(description)
{ {

View File

@ -52,4 +52,4 @@ DEFINE_PROTO_FUZZER(Contract const& _contract)
solAssert(encodeStatus, "Isabelle abicoder fuzzer: Encoding failed"); solAssert(encodeStatus, "Isabelle abicoder fuzzer: Encoding failed");
} }
return; return;
} }

View File

@ -10,14 +10,13 @@ add_dependencies(ossfuzz
strictasm_assembly_ossfuzz strictasm_assembly_ossfuzz
) )
if (OSSFUZZ) if (OSSFUZZ)
add_custom_target(ossfuzz_proto) add_custom_target(ossfuzz_proto)
add_dependencies(ossfuzz_proto add_dependencies(ossfuzz_proto
sol_proto_ossfuzz sol_proto_ossfuzz
yul_proto_ossfuzz yul_proto_ossfuzz
yul_proto_diff_ossfuzz yul_proto_diff_ossfuzz
yul_proto_diff_custom_mutate_ossfuzz yul_proto_diff_custom_mutate_ossfuzz
) )
add_custom_target(ossfuzz_abiv2) add_custom_target(ossfuzz_abiv2)
@ -85,7 +84,7 @@ if (OSSFUZZ)
protobuf.a protobuf.a
) )
set_target_properties(yul_proto_ossfuzz PROPERTIES LINK_FLAGS ${LIB_FUZZING_ENGINE}) set_target_properties(yul_proto_ossfuzz PROPERTIES LINK_FLAGS ${LIB_FUZZING_ENGINE})
target_compile_options(yul_proto_ossfuzz PUBLIC ${COMPILE_OPTIONS} -Wno-sign-conversion) target_compile_options(yul_proto_ossfuzz PUBLIC ${COMPILE_OPTIONS} -Wno-sign-conversion -Wno-suggest-destructor-override -Wno-inconsistent-missing-destructor-override)
add_executable(yul_proto_diff_ossfuzz yulProto_diff_ossfuzz.cpp yulFuzzerCommon.cpp protoToYul.cpp yulProto.pb.cc) 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) target_include_directories(yul_proto_diff_ossfuzz PRIVATE /usr/include/libprotobuf-mutator)
@ -96,7 +95,7 @@ if (OSSFUZZ)
protobuf.a protobuf.a
) )
set_target_properties(yul_proto_diff_ossfuzz PROPERTIES LINK_FLAGS ${LIB_FUZZING_ENGINE}) 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) target_compile_options(yul_proto_diff_ossfuzz PUBLIC ${COMPILE_OPTIONS} -Wno-sign-conversion -Wno-suggest-destructor-override -Wno-inconsistent-missing-destructor-override)
add_executable(yul_proto_diff_custom_mutate_ossfuzz add_executable(yul_proto_diff_custom_mutate_ossfuzz
yulProto_diff_ossfuzz.cpp yulProto_diff_ossfuzz.cpp
@ -113,7 +112,7 @@ if (OSSFUZZ)
protobuf.a protobuf.a
) )
set_target_properties(yul_proto_diff_custom_mutate_ossfuzz PROPERTIES LINK_FLAGS ${LIB_FUZZING_ENGINE}) set_target_properties(yul_proto_diff_custom_mutate_ossfuzz PROPERTIES LINK_FLAGS ${LIB_FUZZING_ENGINE})
target_compile_options(yul_proto_diff_custom_mutate_ossfuzz PUBLIC ${COMPILE_OPTIONS} -Wno-sign-conversion) target_compile_options(yul_proto_diff_custom_mutate_ossfuzz PUBLIC ${COMPILE_OPTIONS} -Wno-sign-conversion -Wno-suggest-destructor-override -Wno-inconsistent-missing-destructor-override)
add_executable(abiv2_proto_ossfuzz add_executable(abiv2_proto_ossfuzz
../../EVMHost.cpp ../../EVMHost.cpp
@ -133,7 +132,7 @@ if (OSSFUZZ)
protobuf.a protobuf.a
) )
set_target_properties(abiv2_proto_ossfuzz PROPERTIES LINK_FLAGS ${LIB_FUZZING_ENGINE}) set_target_properties(abiv2_proto_ossfuzz PROPERTIES LINK_FLAGS ${LIB_FUZZING_ENGINE})
target_compile_options(abiv2_proto_ossfuzz PUBLIC ${COMPILE_OPTIONS} -Wno-sign-conversion) target_compile_options(abiv2_proto_ossfuzz PUBLIC ${COMPILE_OPTIONS} -Wno-sign-conversion -Wno-suggest-destructor-override -Wno-inconsistent-missing-destructor-override)
add_executable(abiv2_isabelle_ossfuzz add_executable(abiv2_isabelle_ossfuzz
../../EVMHost.cpp ../../EVMHost.cpp
@ -155,7 +154,7 @@ if (OSSFUZZ)
gmp gmp
) )
set_target_properties(abiv2_isabelle_ossfuzz PROPERTIES LINK_FLAGS ${LIB_FUZZING_ENGINE}) set_target_properties(abiv2_isabelle_ossfuzz PROPERTIES LINK_FLAGS ${LIB_FUZZING_ENGINE})
target_compile_options(abiv2_isabelle_ossfuzz PUBLIC ${COMPILE_OPTIONS} -Wno-sign-conversion) target_compile_options(abiv2_isabelle_ossfuzz PUBLIC ${COMPILE_OPTIONS} -Wno-sign-conversion -Wno-suggest-destructor-override -Wno-inconsistent-missing-destructor-override)
add_executable(sol_proto_ossfuzz add_executable(sol_proto_ossfuzz
solProtoFuzzer.cpp solProtoFuzzer.cpp
@ -175,7 +174,7 @@ if (OSSFUZZ)
protobuf.a protobuf.a
) )
set_target_properties(sol_proto_ossfuzz PROPERTIES LINK_FLAGS ${LIB_FUZZING_ENGINE}) set_target_properties(sol_proto_ossfuzz PROPERTIES LINK_FLAGS ${LIB_FUZZING_ENGINE})
target_compile_options(sol_proto_ossfuzz PUBLIC ${COMPILE_OPTIONS} -Wno-sign-conversion) target_compile_options(sol_proto_ossfuzz PUBLIC ${COMPILE_OPTIONS} -Wno-sign-conversion -Wno-suggest-destructor-override -Wno-inconsistent-missing-destructor-override)
else() else()
add_library(solc_opt_ossfuzz add_library(solc_opt_ossfuzz
solc_opt_ossfuzz.cpp solc_opt_ossfuzz.cpp

View File

@ -24,10 +24,9 @@
using namespace std; using namespace std;
using namespace solidity::test::fuzzer; using namespace solidity::test::fuzzer;
namespace // Prototype as we can't use the FuzzerInterface.h header.
{
/// Forward declare libFuzzer's default mutator definition
extern "C" size_t LLVMFuzzerMutate(uint8_t* _data, size_t _size, size_t _maxSize); extern "C" size_t LLVMFuzzerMutate(uint8_t* _data, size_t _size, size_t _maxSize);
extern "C" size_t LLVMFuzzerCustomMutator(uint8_t* _data, size_t size, size_t _maxSize, unsigned int seed);
/// Define Solidity's custom mutator by implementing libFuzzer's /// Define Solidity's custom mutator by implementing libFuzzer's
/// custom mutator external interface. /// custom mutator external interface.
@ -42,7 +41,6 @@ extern "C" size_t LLVMFuzzerCustomMutator(
return LLVMFuzzerMutate(_data, _size, _maxSize); return LLVMFuzzerMutate(_data, _size, _maxSize);
return SolidityCustomMutatorInterface{_data, _size, _maxSize, _seed}.generate(); return SolidityCustomMutatorInterface{_data, _size, _maxSize, _seed}.generate();
} }
}
SolidityCustomMutatorInterface::SolidityCustomMutatorInterface( SolidityCustomMutatorInterface::SolidityCustomMutatorInterface(
uint8_t* _data, uint8_t* _data,

View File

@ -32,4 +32,4 @@ string SolidityGenerator::generateTestProgram()
return Whiskers(R"(pragma <directive>;)") return Whiskers(R"(pragma <directive>;)")
("directive", "solidity >= 0.0.0") ("directive", "solidity >= 0.0.0")
.render(); .render();
} }

View File

@ -39,4 +39,4 @@ private:
/// Random number generator /// Random number generator
RandomEngine const m_rand; RandomEngine const m_rand;
}; };
} }

View File

@ -79,4 +79,4 @@ evmc::result AbiV2Utility::deployContract(EVMHost& _hostContext, bytes const& _c
evmc_message message = initializeMessage(_code); evmc_message message = initializeMessage(_code);
message.kind = EVMC_CREATE; message.kind = EVMC_CREATE;
return _hostContext.call(message); return _hostContext.call(message);
} }

View File

@ -20,6 +20,9 @@
using namespace std; using namespace std;
// Prototype as we can't use the FuzzerInterface.h header.
extern "C" int LLVMFuzzerTestOneInput(uint8_t const* _data, size_t _size);
extern "C" int LLVMFuzzerTestOneInput(uint8_t const* _data, size_t _size) extern "C" int LLVMFuzzerTestOneInput(uint8_t const* _data, size_t _size)
{ {
if (_size <= 250) if (_size <= 250)
@ -28,4 +31,4 @@ extern "C" int LLVMFuzzerTestOneInput(uint8_t const* _data, size_t _size)
FuzzerUtil::testConstantOptimizer(input, /*quiet=*/true); FuzzerUtil::testConstantOptimizer(input, /*quiet=*/true);
} }
return 0; return 0;
} }

View File

@ -25,6 +25,9 @@
using namespace solidity::frontend::test; using namespace solidity::frontend::test;
using namespace std; using namespace std;
// Prototype as we can't use the FuzzerInterface.h header.
extern "C" int LLVMFuzzerTestOneInput(uint8_t const* _data, size_t _size);
extern "C" int LLVMFuzzerTestOneInput(uint8_t const* _data, size_t _size) extern "C" int LLVMFuzzerTestOneInput(uint8_t const* _data, size_t _size)
{ {
if (_size <= 600) if (_size <= 600)

View File

@ -25,6 +25,9 @@
using namespace solidity::frontend::test; using namespace solidity::frontend::test;
using namespace std; using namespace std;
// Prototype as we can't use the FuzzerInterface.h header.
extern "C" int LLVMFuzzerTestOneInput(uint8_t const* _data, size_t _size);
extern "C" int LLVMFuzzerTestOneInput(uint8_t const* _data, size_t _size) extern "C" int LLVMFuzzerTestOneInput(uint8_t const* _data, size_t _size)
{ {
if (_size <= 600) if (_size <= 600)

View File

@ -24,6 +24,9 @@ using namespace solidity;
using namespace solidity::yul; using namespace solidity::yul;
using namespace std; using namespace std;
// Prototype as we can't use the FuzzerInterface.h header.
extern "C" int LLVMFuzzerTestOneInput(uint8_t const* _data, size_t _size);
extern "C" int LLVMFuzzerTestOneInput(uint8_t const* _data, size_t _size) extern "C" int LLVMFuzzerTestOneInput(uint8_t const* _data, size_t _size)
{ {
if (_size > 600) if (_size > 600)

View File

@ -44,6 +44,9 @@ using namespace solidity::util;
using namespace solidity::langutil; using namespace solidity::langutil;
using namespace solidity::yul::test::yul_fuzzer; using namespace solidity::yul::test::yul_fuzzer;
// Prototype as we can't use the FuzzerInterface.h header.
extern "C" int LLVMFuzzerTestOneInput(uint8_t const* _data, size_t _size);
extern "C" int LLVMFuzzerTestOneInput(uint8_t const* _data, size_t _size) extern "C" int LLVMFuzzerTestOneInput(uint8_t const* _data, size_t _size)
{ {
if (_size > 600) if (_size > 600)

View File

@ -24,6 +24,9 @@ using namespace solidity::util;
using namespace solidity::yul; using namespace solidity::yul;
using namespace std; using namespace std;
// Prototype as we can't use the FuzzerInterface.h header.
extern "C" int LLVMFuzzerTestOneInput(uint8_t const* _data, size_t _size);
extern "C" int LLVMFuzzerTestOneInput(uint8_t const* _data, size_t _size) extern "C" int LLVMFuzzerTestOneInput(uint8_t const* _data, size_t _size)
{ {
if (_size > 600) if (_size > 600)