From 4e8c2401291eeeb7657e4bcdd0fec9049c415e42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Wed, 9 Aug 2023 12:45:15 +0200 Subject: [PATCH] updated CI to Clang 17 (#4797) --- .clang-tidy | 6 ++ .github/workflows/asan.yml | 6 +- .github/workflows/clang-tidy.yml | 10 +-- .github/workflows/tsan.yml | 6 +- .github/workflows/ubsan.yml | 6 +- clang-tidy.md | 141 +++++++++++++++++-------------- cmake/clang_tidy.cmake | 2 +- lib/tokenlist.cpp | 8 +- 8 files changed, 105 insertions(+), 80 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index fc451fb3c9a..e1bae2cd255 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -20,12 +20,15 @@ Checks: > -zircon-*, cert-err34-c, google-explicit-constructor, + cppcoreguidelines-rvalue-reference-param-not-moved, -bugprone-assignment-in-if-condition, -bugprone-branch-clone, -bugprone-easily-swappable-parameters, + -bugprone-empty-catch, -bugprone-macro-parentheses, -bugprone-narrowing-conversions, -bugprone-signed-char-misuse, + -bugprone-switch-missing-default-case, -bugprone-unchecked-optional-access, -clang-analyzer-*, -concurrency-mt-unsafe, @@ -36,6 +39,7 @@ Checks: > -misc-use-anonymous-namespace, -modernize-avoid-c-arrays, -modernize-deprecated-ios-base-aliases, + -misc-include-cleaner, -modernize-loop-convert, -modernize-raw-string-literal, -modernize-replace-auto-ptr, @@ -43,8 +47,10 @@ Checks: > -modernize-use-auto, -modernize-use-equals-default, -modernize-use-trailing-return-type, + -performance-avoid-endl, -performance-inefficient-string-concatenation, -performance-no-automatic-move, + -performance-noexcept-swap, -portability-simd-intrinsics, -portability-std-allocator-const, -readability-avoid-const-params-in-decls, diff --git a/.github/workflows/asan.yml b/.github/workflows/asan.yml index fdc029ad9f8..fe7c5a95a77 100644 --- a/.github/workflows/asan.yml +++ b/.github/workflows/asan.yml @@ -42,7 +42,7 @@ jobs: sudo apt-get purge --auto-remove llvm python3-lldb-14 llvm-14 wget https://apt.llvm.org/llvm.sh chmod +x llvm.sh - sudo ./llvm.sh 16 + sudo ./llvm.sh 17 - name: Install Qt ${{ env.QT_VERSION }} if: false @@ -56,8 +56,8 @@ jobs: 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 env: - CC: clang-16 - CXX: clang++-16 + CC: clang-17 + CXX: clang++-17 - name: Build cppcheck run: | diff --git a/.github/workflows/clang-tidy.yml b/.github/workflows/clang-tidy.yml index c8546db9ab2..7bcd8bd8e31 100644 --- a/.github/workflows/clang-tidy.yml +++ b/.github/workflows/clang-tidy.yml @@ -30,8 +30,8 @@ jobs: sudo apt-get purge --auto-remove llvm python3-lldb-14 llvm-14 wget https://apt.llvm.org/llvm.sh chmod +x llvm.sh - sudo ./llvm.sh 16 - sudo apt-get install -y clang-tidy-16 + sudo ./llvm.sh 17 + sudo apt-get install -y clang-tidy-17 - name: Install Qt ${{ env.QT_VERSION }} uses: jurplel/install-qt-action@v3 @@ -42,14 +42,14 @@ jobs: - name: Verify clang-tidy configuration run: | - clang-tidy-16 --verify-config + clang-tidy-17 --verify-config - name: Prepare CMake run: | cmake -S . -B cmake.output -G "Unix Makefiles" -DHAVE_RULES=On -DBUILD_TESTS=On -DBUILD_GUI=On -DWITH_QCHART=On -DENABLE_CHECK_INTERNAL=On -DCMAKE_GLOBAL_AUTOGEN_TARGET=On -DCPPCHK_GLIBCXX_DEBUG=Off env: - CC: clang-16 - CXX: clang++-16 + CC: clang-17 + CXX: clang++-17 - name: Prepare CMake dependencies run: | diff --git a/.github/workflows/tsan.yml b/.github/workflows/tsan.yml index 5a5aaa2c900..6114817c194 100644 --- a/.github/workflows/tsan.yml +++ b/.github/workflows/tsan.yml @@ -42,7 +42,7 @@ jobs: sudo apt-get purge --auto-remove llvm python3-lldb-14 llvm-14 wget https://apt.llvm.org/llvm.sh chmod +x llvm.sh - sudo ./llvm.sh 16 + sudo ./llvm.sh 17 - name: Install Qt ${{ env.QT_VERSION }} if: false @@ -56,8 +56,8 @@ jobs: 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_THREAD=On -DUSE_THREADS=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 env: - CC: clang-16 - CXX: clang++-16 + CC: clang-17 + CXX: clang++-17 - name: Build cppcheck run: | diff --git a/.github/workflows/ubsan.yml b/.github/workflows/ubsan.yml index ed6d4e61f6c..3076801002e 100644 --- a/.github/workflows/ubsan.yml +++ b/.github/workflows/ubsan.yml @@ -42,7 +42,7 @@ jobs: sudo apt-get purge --auto-remove llvm python3-lldb-14 llvm-14 wget https://apt.llvm.org/llvm.sh chmod +x llvm.sh - sudo ./llvm.sh 16 + sudo ./llvm.sh 17 - name: Install Qt ${{ env.QT_VERSION }} uses: jurplel/install-qt-action@v3 @@ -55,8 +55,8 @@ jobs: 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 env: - CC: clang-16 - CXX: clang++-16 + CC: clang-17 + CXX: clang++-17 - name: Build cppcheck run: | diff --git a/clang-tidy.md b/clang-tidy.md index 8d1de3c83aa..2311d2d3a97 100644 --- a/clang-tidy.md +++ b/clang-tidy.md @@ -8,156 +8,169 @@ We do not perform static analysis of the source of the external libraries. `simp ## Disabled Checks -`abseil-*`
-`altera-*`
-`android-*`
-`boost-*`
-`darwin-*`
-`fuchsia-*`
-`linuxkernel-*`
-`llvm-*`
-`llvmlibc-*`
-`mpi-*`
-`objc-*`
-`openmp-*`
-`zircon-*`
+`abseil-*`
+`altera-*`
+`android-*`
+`boost-*`
+`darwin-*`
+`fuchsia-*`
+`linuxkernel-*`
+`llvm-*`
+`llvmlibc-*`
+`mpi-*`
+`objc-*`
+`openmp-*`
+`zircon-*`
These are disabled since the platforms/libraries in question are not targeted by us. -`cert-*`
-`cppcoreguidelines-*`
-`google-*`
-`hicpp-*`
+`cert-*`
+`cppcoreguidelines-*`
+`google-*`
+`hicpp-*`
These are coding guidelines we do not follow. Some of the checks might be explicitly enabled though. -`readability-braces-around-statements`
-`readability-isolate-declaration`
-`modernize-use-trailing-return-type`
-`modernize-use-auto`
-`readability-uppercase-literal-suffix`
-`readability-else-after-return`
-`readability-identifier-length`
+`readability-braces-around-statements`
+`readability-isolate-declaration`
+`modernize-use-trailing-return-type`
+`modernize-use-auto`
+`readability-uppercase-literal-suffix`
+`readability-else-after-return`
+`readability-identifier-length`
These do not reflect the style we are (currently) enforcing. -`readability-function-size`
-`readability-function-cognitive-complexity`
+`readability-function-size`
+`readability-function-cognitive-complexity`
We are not interested in the size/complexity of a function. -`readability-magic-numbers`
+`readability-magic-numbers`
These do not (always) increase readability. -`bugprone-macro-parentheses`
+`bugprone-macro-parentheses`
To be documented. -`readability-implicit-bool-conversion`
+`readability-implicit-bool-conversion`
This does not appear to be useful as it is reported on very common code. -`bugprone-narrowing-conversions`
-`performance-no-automatic-move`
+`bugprone-narrowing-conversions`
+`performance-no-automatic-move`
It was decided not to apply these. -`modernize-use-equals-default`
-`modernize-loop-convert`
+`modernize-use-equals-default`
+`modernize-loop-convert`
These might change the behavior of code which might not be intended (need to file an upstream issue) -`modernize-raw-string-literal`
+`modernize-raw-string-literal`
This leads to a mismatch of raw string literals and regular ones and does reduce the readability. -`readability-convert-member-functions-to-static`
+`readability-convert-member-functions-to-static`
Disabled because of false positives with Qt `slot` methods (see https://github.com/llvm/llvm-project/issues/57520). -`-clang-analyzer-*`
+`-clang-analyzer-*`
Disabled because of false positives (needs to file an upstream bug report). -`misc-non-private-member-variables-in-classes`
+`misc-non-private-member-variables-in-classes`
We intentionally use this. -`misc-no-recursion`
+`misc-no-recursion`
Leads to lots of "false positives". This seem to enforce a coding guidelines of certain codebases. -`readability-use-anyofallof`
+`readability-use-anyofallof`
We currently don't even apply our own `useStlAlgorithm` findings. -`bugprone-easily-swappable-parameters`
+`bugprone-easily-swappable-parameters`
This produces a lot of noise and they are not fixable that easily. -`readability-container-data-pointer`
+`readability-container-data-pointer`
Disable because of false positives and inconsistent warnings (need to file an upstream bug report). -`misc-const-correctness`
+`misc-const-correctness`
Work in progress. -`bugprone-assignment-in-if-condition`
+`bugprone-assignment-in-if-condition`
Is reported for valid patterns we are using. -`readability-suspicious-call-argument`
+`readability-suspicious-call-argument`
Produces a lot of false positives since it is too vague in its analysis. -`performance-inefficient-string-concatenation`
+`performance-inefficient-string-concatenation`
Produces warnings which might be considered false positives starting with C++11 - see https://github.com/llvm/llvm-project/issues/54526. -`readability-redundant-access-specifiers`
+`readability-redundant-access-specifiers`
Reports warning with the Qt ` slots:` syntax in class declarations - see https://github.com/llvm/llvm-project/issues/60055. -`modernize-avoid-c-arrays`
+`modernize-avoid-c-arrays`
Produces warnings when `const char[]` is being used which is quite common in our code. Does not make sense to enable before C++17 when `std::string_view` becomes available. Also reports a false positive about templates which deduce the array length: https://github.com/llvm/llvm-project/issues/60053. -`readability-container-size-empty`
-`bugprone-branch-clone`
-`readability-const-return-type`
-`modernize-return-braced-init-list`
-`misc-throw-by-value-catch-by-reference`
-`readability-avoid-const-params-in-decls`
-`bugprone-signed-char-misuse`
-`readability-redundant-access-specifiers`
-`concurrency-mt-unsafe`
-`misc-use-anonymous-namespace`
+`misc-include-cleaner`
-To be evaluated. +We run this separately via `clang-include-cleaner` in the `iwyu.yml` workflow as the findings of the include checkers still need to be reviewed manually before applying them. -`portability-std-allocator-const`
+`readability-container-size-empty`
+`bugprone-branch-clone`
+`readability-const-return-type`
+`modernize-return-braced-init-list`
+`misc-throw-by-value-catch-by-reference`
+`readability-avoid-const-params-in-decls`
+`bugprone-signed-char-misuse`
+`readability-redundant-access-specifiers`
+`concurrency-mt-unsafe`
+`misc-use-anonymous-namespace`
+`performance-avoid-endl`
+`performance-noexcept-swap`
+`bugprone-switch-missing-default-case`
+`bugprone-empty-catch`
+ +To be evaluated (need to remove exclusion). + +`cppcoreguidelines-missing-std-forward`
+`cppcoreguidelines-avoid-const-or-ref-data-members`
+ +To be evaluated (need to enable explicitly). + +`portability-std-allocator-const`
Only necessary for code which is exclusively compiled with `libc++`. Also disabled for performance reasons - see https://github.com/llvm/llvm-project/issues/57527#issuecomment-1237935132. -`modernize-deprecated-ios-base-aliases`
+`modernize-deprecated-ios-base-aliases`
Warns about aliases which are removed in C++20. Also disabled for performance reasons - see https://github.com/llvm/llvm-project/issues/57527#issuecomment-1237935132. -`bugprone-unchecked-optional-access`
+`bugprone-unchecked-optional-access`
We are not using any `optional` implementation. Also disabled for performance reasons - see https://github.com/llvm/llvm-project/issues/57527#issuecomment-1237935132. -`modernize-replace-auto-ptr`
+`modernize-replace-auto-ptr`
Still available until C++17. It is unlikely such code will ever be introduced. Also disabled for performance reasons - see https://github.com/llvm/llvm-project/issues/57527#issuecomment-1237935132. -`readability-identifier-naming`
+`readability-identifier-naming`
We are currently using our own `naming.json` to enforce naming schemes. Also disabled for performance reasons - see https://github.com/llvm/llvm-project/issues/57527#issuecomment-1237935132. -`portability-simd-intrinsics`
+`portability-simd-intrinsics`
We are not using SIMD instructions and it suggests to use `std::experiemental::` features which might not be commonly available. Also disabled for performance reasons - see https://github.com/llvm/llvm-project/issues/57527#issuecomment-1237935132. diff --git a/cmake/clang_tidy.cmake b/cmake/clang_tidy.cmake index 07134ddaa9d..679c14cdb1b 100644 --- a/cmake/clang_tidy.cmake +++ b/cmake/clang_tidy.cmake @@ -9,7 +9,7 @@ if (NOT CMAKE_DISABLE_PRECOMPILE_HEADERS) message(STATUS "Cannot use non-Clang compiler with clang-tidy when precompiled headers are enabled - skipping 'run-clang-tidy' target generation") endif() else() - set(RUN_CLANG_TIDY_NAMES run-clang-tidy run-clang-tidy-16 run-clang-tidy-15 run-clang-tidy-14 run-clang-tidy-13 run-clang-tidy-12 run-clang-tidy-11 run-clang-tidy-10 run-clang-tidy-9 run-clang-tidy-8) + set(RUN_CLANG_TIDY_NAMES run-clang-tidy run-clang-tidy-17 run-clang-tidy-16 run-clang-tidy-15 run-clang-tidy-14 run-clang-tidy-13 run-clang-tidy-12 run-clang-tidy-11 run-clang-tidy-10 run-clang-tidy-9 run-clang-tidy-8) endif() if (RUN_CLANG_TIDY_NAMES) diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 2e023d54841..31077d831f5 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -330,10 +330,15 @@ bool TokenList::createTokens(std::istream &code, const std::string& file0) //--------------------------------------------------------------------------- +// NOLINTNEXTLINE(cppcoreguidelines-rvalue-reference-param-not-moved) void TokenList::createTokens(simplecpp::TokenList&& tokenList) { - if (tokenList.cfront()) + if (tokenList.cfront()) { + // this is a copy + // TODO: the same as TokenList.files - move that instead + // TODO: this points to mFiles when called from createTokens(std::istream &, const std::string&) mOrigFiles = mFiles = tokenList.cfront()->location.files; + } else mFiles.clear(); @@ -341,6 +346,7 @@ void TokenList::createTokens(simplecpp::TokenList&& tokenList) for (const simplecpp::Token *tok = tokenList.cfront(); tok;) { + // TODO: move from TokenList std::string str = tok->str(); // Float literal