mitigated several compiler warnings / suppress compiler warnings in CI where we don't care about them (#5497)

There's no need to generate any warnings in the CI unless we react on
them.
This commit is contained in:
Oliver Stöneberg 2023-10-09 12:25:56 +02:00 committed by GitHub
parent c969c331ea
commit 2f62e9d316
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 47 additions and 28 deletions

View File

@ -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"

View File

@ -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: |

View File

@ -450,7 +450,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: |

View File

@ -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

View File

@ -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:
@ -183,5 +183,5 @@ jobs:
- name: dmake
if: matrix.python-latest
run: |
make -j$(nproc) run-dmake
make -j$(nproc) CXXFLAGS="-w" run-dmake
git diff --exit-code

View File

@ -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

View File

@ -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: |

View File

@ -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)))
@ -575,7 +575,7 @@ $(libcppdir)/ctu.o: lib/ctu.cpp externals/tinyxml2/tinyxml2.h lib/addoninfo.h li
$(libcppdir)/errorlogger.o: lib/errorlogger.cpp externals/tinyxml2/tinyxml2.h lib/addoninfo.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/addoninfo.h 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

View File

@ -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

View File

@ -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) :

View File

@ -18,6 +18,8 @@
#include "keywords.h"
#include "utils.h"
#include <cassert>
// see https://en.cppreference.com/w/c/keyword
@ -164,7 +166,7 @@ const std::unordered_set<std::string>& 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<std::string>& 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<std::string>& 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<std::string>& Keywords::getOnly(Standards::cppstd_t cpp
case Standards::cppstd_t::CPP23:
return cpp23_keywords;
}
assert(false && "unreachable");
cppcheck::unreachable();
}

View File

@ -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(), "&");
});
}

View File

@ -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

View File

@ -589,36 +589,26 @@ 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
// -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");
}