From b714ce4ee37b21f25ecaca050b4b24a7576415a2 Mon Sep 17 00:00:00 2001 From: firewave Date: Fri, 29 Sep 2023 08:51:44 +0200 Subject: [PATCH 1/5] symboldatabase.cpp: fixed Visual Studio unused parameter warning --- lib/symboldatabase.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 1f50548fc5e..43fa58724e2 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -3044,7 +3044,7 @@ bool Function::returnsConst(const Function* function, bool unknown) bool Function::returnsReference(const Function* function, bool unknown, bool includeRValueRef) { - return checkReturns(function, unknown, false, [includeRValueRef](UNUSED const Token* defStart, const Token* defEnd) { + return checkReturns(function, unknown, false, [includeRValueRef](const Token* /*defStart*/, const Token* defEnd) { return includeRValueRef ? Token::Match(defEnd->previous(), "&|&&") : Token::simpleMatch(defEnd->previous(), "&"); }); } From 806ca8863fdfb4a455e65c8c5374bdfe3de547bd Mon Sep 17 00:00:00 2001 From: firewave Date: Wed, 8 Dec 2021 12:37:39 +0100 Subject: [PATCH 2/5] suppress compiler warnings in CI builds where we don't care about them --- .github/workflows/CI-mingw.yml | 1 + .github/workflows/CI-unixish-docker.yml | 4 ++-- .github/workflows/CI-unixish.yml | 2 +- .github/workflows/asan.yml | 1 + .github/workflows/scriptcheck.yml | 4 ++-- .github/workflows/ubsan.yml | 1 + .github/workflows/valgrind.yml | 4 ++-- 7 files changed, 10 insertions(+), 7 deletions(-) diff --git a/.github/workflows/CI-mingw.yml b/.github/workflows/CI-mingw.yml index b5c067dc7a4..75de79ed1f7 100644 --- a/.github/workflows/CI-mingw.yml +++ b/.github/workflows/CI-mingw.yml @@ -47,6 +47,7 @@ jobs: with: key: ${{ github.workflow }}-${{ github.job }}-${{ matrix.os }} + # TODO: bail out on warning - name: Build cppcheck run: | export PATH="/mingw64/lib/ccache/bin:$PATH" diff --git a/.github/workflows/CI-unixish-docker.yml b/.github/workflows/CI-unixish-docker.yml index 9bfc5a017b5..c8095c54a2b 100644 --- a/.github/workflows/CI-unixish-docker.yml +++ b/.github/workflows/CI-unixish-docker.yml @@ -135,13 +135,13 @@ jobs: run: | # "/usr/lib64" for centos / "/usr/lib" for ubuntu export PATH="/usr/lib64/ccache:/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" - make -j$(nproc) HAVE_RULES=yes + make -j$(nproc) HAVE_RULES=yes CXXFLAGS="-w" - name: Build test run: | # "/usr/lib64" for centos / "/usr/lib" for ubuntu export PATH="/usr/lib64/ccache:/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" - make -j$(nproc) testrunner HAVE_RULES=yes + make -j$(nproc) testrunner HAVE_RULES=yes CXXFLAGS="-w" - name: Run test run: | diff --git a/.github/workflows/CI-unixish.yml b/.github/workflows/CI-unixish.yml index 1177c98493d..574def0888d 100644 --- a/.github/workflows/CI-unixish.yml +++ b/.github/workflows/CI-unixish.yml @@ -454,7 +454,7 @@ jobs: run: | export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" # compile with verification and ast matchers - make -j$(nproc) -s CPPFLAGS="-DCHECK_INTERNAL" CXXFLAGS="-g -O2 -DHAVE_BOOST" MATCHCOMPILER=yes VERIFY=1 + make -j$(nproc) -s CPPFLAGS="-DCHECK_INTERNAL" CXXFLAGS="-g -O2 -w -DHAVE_BOOST" MATCHCOMPILER=yes VERIFY=1 - name: Generate UI files run: | diff --git a/.github/workflows/asan.yml b/.github/workflows/asan.yml index 9cb24f42472..4b83c9c81e8 100644 --- a/.github/workflows/asan.yml +++ b/.github/workflows/asan.yml @@ -59,6 +59,7 @@ jobs: modules: 'qtcharts' cache: true + # TODO: disable all warnings - name: CMake run: | cmake -S . -B cmake.output -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHAVE_RULES=On -DBUILD_TESTS=On -DBUILD_GUI=Off -DWITH_QCHART=Off -DUSE_MATCHCOMPILER=Verify -DANALYZE_ADDRESS=On -DENABLE_CHECK_INTERNAL=On -DUSE_BOOST=On -DCPPCHK_GLIBCXX_DEBUG=Off -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On -DCMAKE_GLOBAL_AUTOGEN_TARGET=Off -DDISABLE_DMAKE=On -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache diff --git a/.github/workflows/scriptcheck.yml b/.github/workflows/scriptcheck.yml index caef97642f5..98fc1cd2ee9 100644 --- a/.github/workflows/scriptcheck.yml +++ b/.github/workflows/scriptcheck.yml @@ -37,7 +37,7 @@ jobs: - name: build cppcheck run: | export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" - make -j$(nproc) -s + make -j$(nproc) -s CXXFLAGS="-w" strip -s ./cppcheck scriptcheck: @@ -179,5 +179,5 @@ jobs: - name: dmake if: matrix.python-version == '3.11' run: | - make -j$(nproc) run-dmake + make -j$(nproc) CXXFLAGS="-w" run-dmake git diff --exit-code diff --git a/.github/workflows/ubsan.yml b/.github/workflows/ubsan.yml index 60b1be81eff..ac50e88ef48 100644 --- a/.github/workflows/ubsan.yml +++ b/.github/workflows/ubsan.yml @@ -58,6 +58,7 @@ jobs: modules: 'qtcharts' cache: true + # TODO: disable warnings - name: CMake run: | cmake -S . -B cmake.output -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHAVE_RULES=On -DBUILD_TESTS=On -DBUILD_GUI=ON -DWITH_QCHART=ON -DUSE_MATCHCOMPILER=Verify -DANALYZE_UNDEFINED=On -DENABLE_CHECK_INTERNAL=On -DUSE_BOOST=On -DCPPCHK_GLIBCXX_DEBUG=Off -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On -DCMAKE_GLOBAL_AUTOGEN_TARGET=On -DDISABLE_DMAKE=On -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache diff --git a/.github/workflows/valgrind.yml b/.github/workflows/valgrind.yml index cf03ff89fa3..97f875d5205 100644 --- a/.github/workflows/valgrind.yml +++ b/.github/workflows/valgrind.yml @@ -38,12 +38,12 @@ jobs: - name: Build cppcheck run: | export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" - CXXFLAGS="-O1 -g -DHAVE_BOOST" make -j$(nproc) HAVE_RULES=yes MATCHCOMPILER=yes + CXXFLAGS="-O1 -g -w -DHAVE_BOOST" make -j$(nproc) HAVE_RULES=yes MATCHCOMPILER=yes - name: Build test run: | export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" - CXXFLAGS="-O1 -g -DHAVE_BOOST" make -j$(nproc) testrunner HAVE_RULES=yes MATCHCOMPILER=yes + CXXFLAGS="-O1 -g -w -DHAVE_BOOST" make -j$(nproc) testrunner HAVE_RULES=yes MATCHCOMPILER=yes - name: Run valgrind run: | From 2d9b0fe1035e39ba23a59f9cec19e4a9600755aa Mon Sep 17 00:00:00 2001 From: firewave Date: Fri, 29 Sep 2023 00:41:47 +0200 Subject: [PATCH 3/5] properly suppress "unreachable code" compiler warnings --- Makefile | 2 +- lib/errortypes.cpp | 3 +++ lib/keywords.cpp | 10 ++++++---- lib/utils.h | 14 ++++++++++++++ 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 2e421a3c1d1..b5d93a8755e 100644 --- a/Makefile +++ b/Makefile @@ -567,7 +567,7 @@ $(libcppdir)/ctu.o: lib/ctu.cpp externals/tinyxml2/tinyxml2.h lib/astutils.h lib $(libcppdir)/errorlogger.o: lib/errorlogger.cpp externals/tinyxml2/tinyxml2.h lib/analyzerinfo.h lib/check.h lib/color.h lib/config.h lib/cppcheck.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenlist.h lib/utils.h lib/vfvalue.h $(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/errorlogger.cpp -$(libcppdir)/errortypes.o: lib/errortypes.cpp lib/config.h lib/errortypes.h +$(libcppdir)/errortypes.o: lib/errortypes.cpp lib/config.h lib/errortypes.h lib/utils.h $(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/errortypes.cpp $(libcppdir)/forwardanalyzer.o: lib/forwardanalyzer.cpp lib/analyzer.h lib/astutils.h lib/config.h lib/errortypes.h lib/forwardanalyzer.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/utils.h lib/valueptr.h lib/vfvalue.h diff --git a/lib/errortypes.cpp b/lib/errortypes.cpp index cd9ca57711e..1653df844bd 100644 --- a/lib/errortypes.cpp +++ b/lib/errortypes.cpp @@ -18,6 +18,8 @@ #include "errortypes.h" +#include "utils.h" + static std::string typeToString(InternalError::Type type) { switch (type) { @@ -34,6 +36,7 @@ static std::string typeToString(InternalError::Type type) case InternalError::Type::INSTANTIATION: return "instantiationError"; } + cppcheck::unreachable(); } InternalError::InternalError(const Token *tok, std::string errorMsg, Type type) : diff --git a/lib/keywords.cpp b/lib/keywords.cpp index 87f1bef35d4..192b5faac81 100644 --- a/lib/keywords.cpp +++ b/lib/keywords.cpp @@ -18,6 +18,8 @@ #include "keywords.h" +#include "utils.h" + #include // see https://en.cppreference.com/w/c/keyword @@ -164,7 +166,7 @@ const std::unordered_set& Keywords::getAll(Standards::cstd_t cStd) /*case Standards::cstd_t::C23: return c23_keywords_all;*/ } - assert(false && "unreachable"); + cppcheck::unreachable(); } // cppcheck-suppress unusedFunction @@ -184,7 +186,7 @@ const std::unordered_set& Keywords::getAll(Standards::cppstd_t cppS case Standards::cppstd_t::CPP23: return cpp23_keywords_all; } - assert(false && "unreachable"); + cppcheck::unreachable(); } // cppcheck-suppress unusedFunction @@ -201,7 +203,7 @@ const std::unordered_set& Keywords::getOnly(Standards::cstd_t cStd) /*case Standards::cstd_t::C23: return c23_keywords_all;*/ } - assert(false && "unreachable"); + cppcheck::unreachable(); } // cppcheck-suppress unusedFunction @@ -222,6 +224,6 @@ const std::unordered_set& Keywords::getOnly(Standards::cppstd_t cpp case Standards::cppstd_t::CPP23: return cpp23_keywords; } - assert(false && "unreachable"); + cppcheck::unreachable(); } diff --git a/lib/utils.h b/lib/utils.h index 5218ab1c47a..2ac0df275c9 100644 --- a/lib/utils.h +++ b/lib/utils.h @@ -331,4 +331,18 @@ static inline const char* bool_to_string(bool b) return b ? "true" : "false"; } +namespace cppcheck +{ + NORETURN inline void unreachable() + { +#if defined(__GNUC__) + __builtin_unreachable(); +#elif defined(_MSC_VER) + __assume(false); +#else +#error "no unreachable implementation" +#endif + } +} + #endif From da847bc282245b03bd3b98ff3cff0cf271ae1430 Mon Sep 17 00:00:00 2001 From: firewave Date: Fri, 29 Sep 2023 08:57:34 +0200 Subject: [PATCH 4/5] dmake: suppress `-Wmultichar` in release builds --- tools/dmake.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/dmake.cpp b/tools/dmake.cpp index 0072f211f76..1f4953e8f19 100644 --- a/tools/dmake.cpp +++ b/tools/dmake.cpp @@ -589,7 +589,7 @@ int main(int argc, char **argv) // Makefile settings.. if (release) { - makeConditionalVariable(fout, "CXXFLAGS", "-std=c++0x -O2 -DNDEBUG -Wall -Wno-sign-compare"); + makeConditionalVariable(fout, "CXXFLAGS", "-std=c++0x -O2 -DNDEBUG -Wall -Wno-sign-compare -Wno-multichar"); } else { // TODO: add more compiler warnings. // -Wlogical-op : doesn't work on older GCC From 6d75912b919d623b8b9042c7bff02aab76f8c5a8 Mon Sep 17 00:00:00 2001 From: firewave Date: Fri, 29 Sep 2023 09:26:37 +0200 Subject: [PATCH 5/5] aligned CMake and Makefile compiler warnings --- Makefile | 2 +- cmake/compileroptions.cmake | 9 ++++++++- tools/dmake.cpp | 14 ++------------ 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index b5d93a8755e..9d9cc563f27 100644 --- a/Makefile +++ b/Makefile @@ -137,7 +137,7 @@ ifeq (clang++, $(findstring clang++,$(CXX))) CPPCHK_GLIBCXX_DEBUG= endif ifndef CXXFLAGS - CXXFLAGS=-pedantic -Wall -Wextra -Wcast-qual -Wno-deprecated-declarations -Wfloat-equal -Wmissing-declarations -Wmissing-format-attribute -Wno-long-long -Wpacked -Wredundant-decls -Wundef -Wno-shadow -Wno-missing-field-initializers -Wno-missing-braces -Wno-sign-compare -Wno-multichar $(CPPCHK_GLIBCXX_DEBUG) -g + CXXFLAGS=-pedantic -Wall -Wextra -Wcast-qual -Wfloat-equal -Wmissing-declarations -Wmissing-format-attribute -Wno-long-long -Wpacked -Wredundant-decls -Wundef -Wno-shadow -Wno-missing-field-initializers -Wno-missing-braces -Wno-sign-compare -Wno-multichar -Woverloaded-virtual $(CPPCHK_GLIBCXX_DEBUG) -g endif ifeq (g++, $(findstring g++,$(CXX))) diff --git a/cmake/compileroptions.cmake b/cmake/compileroptions.cmake index 4c5ad9af858..38df5d106dd 100644 --- a/cmake/compileroptions.cmake +++ b/cmake/compileroptions.cmake @@ -43,13 +43,20 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang add_compile_options(-Wno-missing-braces) add_compile_options(-Wno-sign-compare) add_compile_options(-Wno-multichar) + add_compile_options(-Woverloaded-virtual) # when a function declaration hides virtual functions from a base class + + # TODO: evaluate + #add_compile_options(-Wconversion) # danmar: gives fp. for instance: unsigned int sizeof_pointer = sizeof(void *); + #add_compile_options(-Wlogical-op) # doesn't work on older GCC + #add_compile_options(-Wsign-conversion) # too many warnings + #add_compile_options(-Wunreachable-code) # some GCC versions report lots of warnings + #add_compile_options(-Wsign-promo) endif() if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") # use pipes instead of temporary files - greatly reduces I/O usage add_compile_options(-pipe) - add_compile_options(-Woverloaded-virtual) # when a function declaration hides virtual functions from a base class add_compile_options(-Wno-maybe-uninitialized) # there are some false positives add_compile_options(-Wsuggest-attribute=noreturn) add_compile_options(-Wno-shadow) # whenever a local variable or type declaration shadows another one diff --git a/tools/dmake.cpp b/tools/dmake.cpp index 1f4953e8f19..c9b47989e24 100644 --- a/tools/dmake.cpp +++ b/tools/dmake.cpp @@ -591,34 +591,24 @@ int main(int argc, char **argv) if (release) { makeConditionalVariable(fout, "CXXFLAGS", "-std=c++0x -O2 -DNDEBUG -Wall -Wno-sign-compare -Wno-multichar"); } else { - // TODO: add more compiler warnings. - // -Wlogical-op : doesn't work on older GCC - // -Wsign-conversion : too many warnings - // -Wunreachable-code : some GCC versions report lots of warnings makeConditionalVariable(fout, "CXXFLAGS", "-pedantic " "-Wall " "-Wextra " "-Wcast-qual " -// "-Wconversion " // danmar: gives fp. for instance: unsigned int sizeof_pointer = sizeof(void *); - "-Wno-deprecated-declarations " "-Wfloat-equal " -// "-Wlogical-op " "-Wmissing-declarations " "-Wmissing-format-attribute " "-Wno-long-long " -// "-Woverloaded-virtual " // danmar: we get fp when overloading analyseWholeProgram() "-Wpacked " "-Wredundant-decls " "-Wundef " "-Wno-shadow " -// "-Wsign-conversion " -// "-Wsign-promo " "-Wno-missing-field-initializers " "-Wno-missing-braces " -// "-Wunreachable-code " - "-Wno-sign-compare " // danmar: I don't like this warning, it's very rarely a bug + "-Wno-sign-compare " "-Wno-multichar " + "-Woverloaded-virtual " "$(CPPCHK_GLIBCXX_DEBUG) " "-g"); }