diff --git a/cmake/EthCompilerSettings.cmake b/cmake/EthCompilerSettings.cmake index 066ca74d8..adbc3a661 100644 --- a/cmake/EthCompilerSettings.cmake +++ b/cmake/EthCompilerSettings.cmake @@ -48,6 +48,7 @@ if (("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") OR ("${CMAKE_CXX_COMPILER_ID}" MA add_compile_options(-Wextra) add_compile_options(-Werror) add_compile_options(-pedantic) + add_compile_options(-Wmissing-declarations) add_compile_options(-Wno-unknown-pragmas) add_compile_options(-Wimplicit-fallthrough) 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( $<$:-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. set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g3 -DETH_DEBUG") diff --git a/liblangutil/Token.cpp b/liblangutil/Token.cpp index bbcfe1590..28180514a 100644 --- a/liblangutil/Token.cpp +++ b/liblangutil/Token.cpp @@ -126,6 +126,8 @@ int precedence(Token tok) } #undef T +namespace +{ int parseSize(string::const_iterator _begin, string::const_iterator _end) { try @@ -138,6 +140,7 @@ int parseSize(string::const_iterator _begin, string::const_iterator _end) return -1; } } +} static Token keywordByName(string const& _name) { diff --git a/libsolidity/analysis/GlobalContext.cpp b/libsolidity/analysis/GlobalContext.cpp index dee7e8220..aef68fe25 100644 --- a/libsolidity/analysis/GlobalContext.cpp +++ b/libsolidity/analysis/GlobalContext.cpp @@ -34,6 +34,8 @@ using namespace std; namespace solidity::frontend { +namespace +{ /// Magic variables get negative ids for easy differentiation int magicVariableToID(std::string const& _name) { @@ -113,6 +115,8 @@ inline vector> constructMagicVariable }; } +} + GlobalContext::GlobalContext(): m_magicVariables{constructMagicVariables()} { } diff --git a/libsolidity/formal/SymbolicVariables.cpp b/libsolidity/formal/SymbolicVariables.cpp index 5c23fbf66..8f78495a9 100644 --- a/libsolidity/formal/SymbolicVariables.cpp +++ b/libsolidity/formal/SymbolicVariables.cpp @@ -399,4 +399,4 @@ smtutil::Expression SymbolicStructVariable::assignAllMembers(vectorname())); return currentValue(); -} \ No newline at end of file +} diff --git a/libsolutil/UTF8.cpp b/libsolutil/UTF8.cpp index 4acf7a8ea..baeda14b0 100644 --- a/libsolutil/UTF8.cpp +++ b/libsolutil/UTF8.cpp @@ -76,8 +76,6 @@ bool isWellFormed(unsigned char byte1, unsigned char byte2) return false; } -} - bool validateUTF8(unsigned char const* _input, size_t _length, size_t& _invalidPosition) { bool valid = true; @@ -134,6 +132,8 @@ bool validateUTF8(unsigned char const* _input, size_t _length, size_t& _invalidP return false; } +} + bool validateUTF8(std::string const& _input, size_t& _invalidPosition) { return validateUTF8(reinterpret_cast(_input.c_str()), _input.length(), _invalidPosition); diff --git a/libyul/optimiser/FunctionCallFinder.cpp b/libyul/optimiser/FunctionCallFinder.cpp index 4bc1998b1..b8f206440 100644 --- a/libyul/optimiser/FunctionCallFinder.cpp +++ b/libyul/optimiser/FunctionCallFinder.cpp @@ -36,4 +36,4 @@ void FunctionCallFinder::operator()(FunctionCall& _functionCall) ASTModifier::operator()(_functionCall); if (_functionCall.functionName.name == m_functionName) m_calls.emplace_back(&_functionCall); -} \ No newline at end of file +} diff --git a/libyul/optimiser/StackToMemoryMover.h b/libyul/optimiser/StackToMemoryMover.h index 5cbc5a5a0..2ec831946 100644 --- a/libyul/optimiser/StackToMemoryMover.h +++ b/libyul/optimiser/StackToMemoryMover.h @@ -129,4 +129,4 @@ private: NameDispenser& m_nameDispenser; }; -} \ No newline at end of file +} diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index b74cc224f..238cd6541 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -92,6 +92,9 @@ namespace solidity::frontend bool g_hasOutput = false; +namespace +{ + std::ostream& sout() { g_hasOutput = true; @@ -105,6 +108,8 @@ std::ostream& serr(bool _used = true) return cerr; } +} + #define cout #define cerr @@ -329,6 +334,9 @@ static bool needsHumanTargetedStdout(po::variables_map const& _args) return false; } +namespace +{ + bool checkMutuallyExclusive(boost::program_options::variables_map const& args, std::string const& _optionA, std::string const& _optionB) { if (args.count(_optionA) && args.count(_optionB)) @@ -340,6 +348,8 @@ bool checkMutuallyExclusive(boost::program_options::variables_map const& args, s return true; } +} + void CommandLineInterface::handleBinary(string const& _contract) { if (m_args.count(g_argBinary)) diff --git a/test/Common.cpp b/test/Common.cpp index 5e7059013..4be957a03 100644 --- a/test/Common.cpp +++ b/test/Common.cpp @@ -30,6 +30,9 @@ namespace po = boost::program_options; namespace solidity::test { +namespace +{ + /// 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" /// and returns it if found. @@ -84,6 +87,8 @@ std::string envOrDefaultPath(std::string const& env_name, std::string const& lib return {}; } +} + CommonOptions::CommonOptions(std::string _caption): options(_caption, po::options_description::m_default_line_length, diff --git a/test/boostTest.cpp b/test/boostTest.cpp index 81aae19ab..36620337e 100644 --- a/test/boostTest.cpp +++ b/test/boostTest.cpp @@ -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*/[] ) { master_test_suite_t& master = framework::master_test_suite(); diff --git a/test/evmc/CMakeLists.txt b/test/evmc/CMakeLists.txt index bd64e8625..b49b85a29 100644 --- a/test/evmc/CMakeLists.txt +++ b/test/evmc/CMakeLists.txt @@ -19,4 +19,4 @@ target_sources(evmc INTERFACE ${PROJECT_SOURCE_DIR}/test/evmc/utils.h ) target_include_directories(evmc INTERFACE ${PROJECT_SOURCE_DIR}/test/) -target_link_libraries(evmc INTERFACE evmc_loader) \ No newline at end of file +target_link_libraries(evmc INTERFACE evmc_loader) diff --git a/test/libsolidity/SemVerMatcher.cpp b/test/libsolidity/SemVerMatcher.cpp index a3e1661ef..5337c844a 100644 --- a/test/libsolidity/SemVerMatcher.cpp +++ b/test/libsolidity/SemVerMatcher.cpp @@ -38,6 +38,9 @@ namespace solidity::frontend::test BOOST_AUTO_TEST_SUITE(SemVerMatcher) +namespace +{ + SemVerMatchExpression parseExpression(string const& _input) { Scanner scanner{CharStream(_input, "")}; @@ -62,6 +65,8 @@ SemVerMatchExpression parseExpression(string const& _input) return expression; } +} + BOOST_AUTO_TEST_CASE(positive_range) { // Positive range tests diff --git a/test/libsolidity/util/TestFileParserTests.cpp b/test/libsolidity/util/TestFileParserTests.cpp index cf83d3029..242b721b9 100644 --- a/test/libsolidity/util/TestFileParserTests.cpp +++ b/test/libsolidity/util/TestFileParserTests.cpp @@ -39,6 +39,9 @@ namespace solidity::frontend::test using fmt = ExecutionFramework; using Mode = FunctionCall::DisplayMode; +namespace +{ + vector parse(string const& _source) { istringstream stream{_source, ios_base::out}; @@ -86,6 +89,8 @@ void testFunctionCall( BOOST_REQUIRE_EQUAL(_call.kind == FunctionCall::Kind::Library, _isLibrary); } +} + BOOST_AUTO_TEST_SUITE(TestFileParserTest) BOOST_AUTO_TEST_CASE(smoke_test) diff --git a/test/libsolutil/SwarmHash.cpp b/test/libsolutil/SwarmHash.cpp index 3b13cd382..5d0c22a80 100644 --- a/test/libsolutil/SwarmHash.cpp +++ b/test/libsolutil/SwarmHash.cpp @@ -34,6 +34,9 @@ namespace solidity::util::test BOOST_AUTO_TEST_SUITE(SwarmHash, *boost::unit_test::label("nooptions")) +namespace +{ + string bzzr0HashHex(string const& _input) { return toHex(bzzr0Hash(_input).asBytes()); @@ -52,6 +55,8 @@ bytes sequence(size_t _length) return data; } +} + BOOST_AUTO_TEST_CASE(test_zeros) { BOOST_CHECK_EQUAL(bzzr0HashHex(string()), string("011b4d03dd8c01f1049143cf9c4c817e4b167f1d1b83e5c6f0f10d89ba1e7bce")); diff --git a/test/tools/IsolTestOptions.cpp b/test/tools/IsolTestOptions.cpp index 943832677..763a0b3b7 100644 --- a/test/tools/IsolTestOptions.cpp +++ b/test/tools/IsolTestOptions.cpp @@ -35,6 +35,9 @@ namespace po = boost::program_options; namespace solidity::test { +namespace +{ + auto const description = R"(isoltest, tool for interactively managing test contracts. Usage: isoltest [Options] Interactively validates test contracts. @@ -51,6 +54,8 @@ std::string editorPath() return std::string{}; } +} + IsolTestOptions::IsolTestOptions(std::string* _editor): CommonOptions(description) { diff --git a/test/tools/ossfuzz/AbiV2IsabelleFuzzer.cpp b/test/tools/ossfuzz/AbiV2IsabelleFuzzer.cpp index 4e28c444b..87b7fd913 100644 --- a/test/tools/ossfuzz/AbiV2IsabelleFuzzer.cpp +++ b/test/tools/ossfuzz/AbiV2IsabelleFuzzer.cpp @@ -52,4 +52,4 @@ DEFINE_PROTO_FUZZER(Contract const& _contract) solAssert(encodeStatus, "Isabelle abicoder fuzzer: Encoding failed"); } return; -} \ No newline at end of file +} diff --git a/test/tools/ossfuzz/CMakeLists.txt b/test/tools/ossfuzz/CMakeLists.txt index 0e1238ee8..3d205722b 100644 --- a/test/tools/ossfuzz/CMakeLists.txt +++ b/test/tools/ossfuzz/CMakeLists.txt @@ -10,14 +10,13 @@ add_dependencies(ossfuzz strictasm_assembly_ossfuzz ) - if (OSSFUZZ) add_custom_target(ossfuzz_proto) add_dependencies(ossfuzz_proto - sol_proto_ossfuzz - yul_proto_ossfuzz - yul_proto_diff_ossfuzz - yul_proto_diff_custom_mutate_ossfuzz + sol_proto_ossfuzz + yul_proto_ossfuzz + yul_proto_diff_ossfuzz + yul_proto_diff_custom_mutate_ossfuzz ) add_custom_target(ossfuzz_abiv2) @@ -85,7 +84,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) + 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) target_include_directories(yul_proto_diff_ossfuzz PRIVATE /usr/include/libprotobuf-mutator) @@ -96,7 +95,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) + 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 yulProto_diff_ossfuzz.cpp @@ -113,7 +112,7 @@ if (OSSFUZZ) protobuf.a ) 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 ../../EVMHost.cpp @@ -133,7 +132,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) + 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 ../../EVMHost.cpp @@ -155,7 +154,7 @@ if (OSSFUZZ) gmp ) 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 solProtoFuzzer.cpp @@ -175,7 +174,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) + target_compile_options(sol_proto_ossfuzz PUBLIC ${COMPILE_OPTIONS} -Wno-sign-conversion -Wno-suggest-destructor-override -Wno-inconsistent-missing-destructor-override) else() add_library(solc_opt_ossfuzz solc_opt_ossfuzz.cpp diff --git a/test/tools/ossfuzz/SolidityCustomMutatorInterface.cpp b/test/tools/ossfuzz/SolidityCustomMutatorInterface.cpp index ac56860b9..16c71f970 100644 --- a/test/tools/ossfuzz/SolidityCustomMutatorInterface.cpp +++ b/test/tools/ossfuzz/SolidityCustomMutatorInterface.cpp @@ -24,10 +24,9 @@ using namespace std; using namespace solidity::test::fuzzer; -namespace -{ -/// Forward declare libFuzzer's default mutator definition +// Prototype as we can't use the FuzzerInterface.h header. 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 /// custom mutator external interface. @@ -42,7 +41,6 @@ extern "C" size_t LLVMFuzzerCustomMutator( return LLVMFuzzerMutate(_data, _size, _maxSize); return SolidityCustomMutatorInterface{_data, _size, _maxSize, _seed}.generate(); } -} SolidityCustomMutatorInterface::SolidityCustomMutatorInterface( uint8_t* _data, diff --git a/test/tools/ossfuzz/SolidityGenerator.cpp b/test/tools/ossfuzz/SolidityGenerator.cpp index f9c43ef66..6e9198b87 100644 --- a/test/tools/ossfuzz/SolidityGenerator.cpp +++ b/test/tools/ossfuzz/SolidityGenerator.cpp @@ -32,4 +32,4 @@ string SolidityGenerator::generateTestProgram() return Whiskers(R"(pragma ;)") ("directive", "solidity >= 0.0.0") .render(); -} \ No newline at end of file +} diff --git a/test/tools/ossfuzz/SolidityGenerator.h b/test/tools/ossfuzz/SolidityGenerator.h index 5b7abce04..55c3c1f3a 100644 --- a/test/tools/ossfuzz/SolidityGenerator.h +++ b/test/tools/ossfuzz/SolidityGenerator.h @@ -39,4 +39,4 @@ private: /// Random number generator RandomEngine const m_rand; }; -} \ No newline at end of file +} diff --git a/test/tools/ossfuzz/abiV2FuzzerCommon.cpp b/test/tools/ossfuzz/abiV2FuzzerCommon.cpp index 9e506b7d7..ac354c029 100644 --- a/test/tools/ossfuzz/abiV2FuzzerCommon.cpp +++ b/test/tools/ossfuzz/abiV2FuzzerCommon.cpp @@ -79,4 +79,4 @@ evmc::result AbiV2Utility::deployContract(EVMHost& _hostContext, bytes const& _c evmc_message message = initializeMessage(_code); message.kind = EVMC_CREATE; return _hostContext.call(message); -} \ No newline at end of file +} diff --git a/test/tools/ossfuzz/const_opt_ossfuzz.cpp b/test/tools/ossfuzz/const_opt_ossfuzz.cpp index 60b1febbc..0b799c956 100644 --- a/test/tools/ossfuzz/const_opt_ossfuzz.cpp +++ b/test/tools/ossfuzz/const_opt_ossfuzz.cpp @@ -20,6 +20,9 @@ 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) { if (_size <= 250) @@ -28,4 +31,4 @@ extern "C" int LLVMFuzzerTestOneInput(uint8_t const* _data, size_t _size) FuzzerUtil::testConstantOptimizer(input, /*quiet=*/true); } return 0; -} \ No newline at end of file +} diff --git a/test/tools/ossfuzz/solc_noopt_ossfuzz.cpp b/test/tools/ossfuzz/solc_noopt_ossfuzz.cpp index 4261f60d3..8d9e098ce 100644 --- a/test/tools/ossfuzz/solc_noopt_ossfuzz.cpp +++ b/test/tools/ossfuzz/solc_noopt_ossfuzz.cpp @@ -25,6 +25,9 @@ using namespace solidity::frontend::test; 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) { if (_size <= 600) diff --git a/test/tools/ossfuzz/solc_opt_ossfuzz.cpp b/test/tools/ossfuzz/solc_opt_ossfuzz.cpp index 5cd8e3460..78a0772bf 100644 --- a/test/tools/ossfuzz/solc_opt_ossfuzz.cpp +++ b/test/tools/ossfuzz/solc_opt_ossfuzz.cpp @@ -25,6 +25,9 @@ using namespace solidity::frontend::test; 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) { if (_size <= 600) diff --git a/test/tools/ossfuzz/strictasm_assembly_ossfuzz.cpp b/test/tools/ossfuzz/strictasm_assembly_ossfuzz.cpp index 458bde745..e25de4f05 100644 --- a/test/tools/ossfuzz/strictasm_assembly_ossfuzz.cpp +++ b/test/tools/ossfuzz/strictasm_assembly_ossfuzz.cpp @@ -24,6 +24,9 @@ using namespace solidity; using namespace solidity::yul; 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) { if (_size > 600) diff --git a/test/tools/ossfuzz/strictasm_diff_ossfuzz.cpp b/test/tools/ossfuzz/strictasm_diff_ossfuzz.cpp index bd6d249b3..7372e17f0 100644 --- a/test/tools/ossfuzz/strictasm_diff_ossfuzz.cpp +++ b/test/tools/ossfuzz/strictasm_diff_ossfuzz.cpp @@ -44,6 +44,9 @@ using namespace solidity::util; using namespace solidity::langutil; 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) { if (_size > 600) diff --git a/test/tools/ossfuzz/strictasm_opt_ossfuzz.cpp b/test/tools/ossfuzz/strictasm_opt_ossfuzz.cpp index 646e6ea6a..b1aa9a21f 100644 --- a/test/tools/ossfuzz/strictasm_opt_ossfuzz.cpp +++ b/test/tools/ossfuzz/strictasm_opt_ossfuzz.cpp @@ -24,6 +24,9 @@ using namespace solidity::util; using namespace solidity::yul; 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) { if (_size > 600)