Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 5 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/CI-mingw.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/CI-unixish-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/CI-unixish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/asan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/scriptcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
1 change: 1 addition & 0 deletions .github/workflows/ubsan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/valgrind.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion cmake/compileroptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions lib/errortypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

#include "errortypes.h"

#include "utils.h"

static std::string typeToString(InternalError::Type type)
{
switch (type) {
Expand All @@ -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) :
Expand Down
10 changes: 6 additions & 4 deletions lib/keywords.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

#include "keywords.h"

#include "utils.h"

#include <cassert>

// see https://en.cppreference.com/w/c/keyword
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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();
}

2 changes: 1 addition & 1 deletion lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(), "&");
});
}
Expand Down
14 changes: 14 additions & 0 deletions lib/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
danmar marked this conversation as resolved.
Show resolved Hide resolved
#elif defined(_MSC_VER)
__assume(false);
#else
#error "no unreachable implementation"
#endif
}
}

#endif
16 changes: 3 additions & 13 deletions tools/dmake.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
Loading