diff --git a/.github/workflows/testing-arm-linux.yml b/.github/workflows/testing-arm-linux.yml index 9aaeaf3af553..1ecd6f09309f 100644 --- a/.github/workflows/testing-arm-linux.yml +++ b/.github/workflows/testing-arm-linux.yml @@ -17,6 +17,8 @@ on: - "packaging/**" - "Makefile" - "Makefile.inc" + - 'run-clang-tidy.sh' + - '**.clang-tidy' concurrency: group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} diff --git a/.github/workflows/testing-linux.yml b/.github/workflows/testing-linux.yml index b0984bc5fb3d..120e3ed035f7 100644 --- a/.github/workflows/testing-linux.yml +++ b/.github/workflows/testing-linux.yml @@ -17,6 +17,8 @@ on: - "packaging/**" - "Makefile" - "Makefile.inc" + - 'run-clang-tidy.sh' + - '**.clang-tidy' concurrency: group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} diff --git a/.github/workflows/testing-windows.yml b/.github/workflows/testing-windows.yml index 105bb3d5fd02..4135d5cda31e 100644 --- a/.github/workflows/testing-windows.yml +++ b/.github/workflows/testing-windows.yml @@ -17,6 +17,8 @@ on: - "packaging/**" - "Makefile" - "Makefile.inc" + - 'run-clang-tidy.sh' + - '**.clang-tidy' concurrency: group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} diff --git a/run-clang-tidy.sh b/run-clang-tidy.sh index 17d19db7b48a..7f261529a959 100755 --- a/run-clang-tidy.sh +++ b/run-clang-tidy.sh @@ -1,7 +1,12 @@ -#!/bin/bash +#!/usr/bin/env bash set -e +CLEANUP_FILES=() +# shellcheck disable=SC2329 +cleanup() { rm -rf "${CLEANUP_FILES[@]}"; } +trap cleanup EXIT + ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" ## @@ -36,12 +41,8 @@ get_thread_count() { } if [ "$(uname)" == "Darwin" ]; then - # shellcheck disable=SC2329 - patch_file() { sed -i '' -E "$@"; } _DEFAULT_LLVM_LOCATION="/opt/homebrew/opt/llvm@$EXPECTED_VERSION" else - # shellcheck disable=SC2329 - patch_file() { sed -i -E "$@"; } _DEFAULT_LLVM_LOCATION="/usr/lib/llvm-$EXPECTED_VERSION" fi @@ -94,7 +95,7 @@ fi # Use a temp folder for the CMake stuff here, so it's fresh & correct every time if [[ -z ${CLANG_TIDY_BUILD_DIR} ]]; then CLANG_TIDY_BUILD_DIR=$(mktemp -d) - trap 'rm -rf ${CLANG_TIDY_BUILD_DIR}' EXIT + CLEANUP_FILES+=("${CLANG_TIDY_BUILD_DIR}") else mkdir -p "${CLANG_TIDY_BUILD_DIR}" fi @@ -141,34 +142,33 @@ cmake -S "${ROOT_DIR}" -B "${CLANG_TIDY_BUILD_DIR}" -Wno-dev -DWITH_TESTS=OFF echo Building Halide... cmake --build "${CLANG_TIDY_BUILD_DIR}" -j "${J}" -echo Building runtime compilation database... -temp_file=$(mktemp) -trap 'rm -f $temp_file' EXIT -rm -f "${CLANG_TIDY_BUILD_DIR}/src/runtime/compile_commands.json" -cat "${CLANG_TIDY_BUILD_DIR}"/src/runtime/*.json >"$temp_file" -{ - echo '[' - cat "$temp_file" | sed '$ s/,$//' - echo ']' -} >"${CLANG_TIDY_BUILD_DIR}/src/runtime/compile_commands.json" - -echo Merging compilation databases... +echo Merging runtime compilation database... jq -s 'add' "${CLANG_TIDY_BUILD_DIR}/compile_commands.json" \ - "${CLANG_TIDY_BUILD_DIR}/src/runtime/compile_commands.json" \ + <(sed 's/,$//' "${CLANG_TIDY_BUILD_DIR}"/src/runtime/*.json | jq -s '.') \ >"${CLANG_TIDY_BUILD_DIR}/compile_commands_merged.json" mv "${CLANG_TIDY_BUILD_DIR}/compile_commands_merged.json" "${CLANG_TIDY_BUILD_DIR}/compile_commands.json" +# Wrapper filters noisy "N warnings generated." from each clang-tidy invocation. +CLANG_TIDY_FILTER="${CLANG_TIDY_BUILD_DIR}/clang-tidy-filter.sh" +cat >"${CLANG_TIDY_FILTER}" <&1 | grep -v '^[[:digit:]]\+ warnings\? generated\.\$' +exit "\${PIPESTATUS[0]}" +WRAPPER +chmod +x "${CLANG_TIDY_FILTER}" + echo Running clang-tidy... -PYTHONUNBUFFERED=1 "${CLANG_TIDY_LLVM_INSTALL_DIR}/bin/run-clang-tidy" \ +export PYTHONUNBUFFERED=1 +"${CLANG_TIDY_LLVM_INSTALL_DIR}/bin/run-clang-tidy" \ ${FIX} \ -j "${J}" \ -quiet \ -p "${CLANG_TIDY_BUILD_DIR}" \ - -clang-tidy-binary "${CLANG_TIDY_LLVM_INSTALL_DIR}/bin/clang-tidy" \ + -clang-tidy-binary "${CLANG_TIDY_FILTER}" \ -clang-apply-replacements-binary "${CLANG_TIDY_LLVM_INSTALL_DIR}/bin/clang-apply-replacements" \ - "$@" 2>&1 | sed -Eu '/^[[:digit:]]+ warnings? generated\.$/{N;/\n$/d;}' + "$@" -CLANG_TIDY_EXIT_CODE=${PIPESTATUS[0]} +CLANG_TIDY_EXIT_CODE=$? if [ "$CLANG_TIDY_EXIT_CODE" -eq 0 ]; then echo "Success!" diff --git a/src/runtime/.clang-tidy b/src/runtime/.clang-tidy index 1b22ac06f1bc..ea7f4e5d3986 100644 --- a/src/runtime/.clang-tidy +++ b/src/runtime/.clang-tidy @@ -2,91 +2,30 @@ InheritParentConfig: true # keep-sorted start skip_lines=1 ignore_prefixes=- Checks: > - bugprone-argument-comment, - bugprone-assert-side-effect, + bugprone-*, -bugprone-assignment-in-if-condition, - bugprone-bad-signal-to-kill-thread, - bugprone-bool-pointer-implicit-conversion, + -bugprone-bitwise-pointer-cast, -bugprone-branch-clone, - bugprone-copy-constructor-init, - bugprone-dangling-handle, -bugprone-dynamic-static-initializers, -bugprone-easily-swappable-parameters, -bugprone-exception-escape, - bugprone-fold-init-type, - bugprone-forward-declaration-namespace, - bugprone-forwarding-reference-overload, -bugprone-implicit-widening-of-multiplication-result, - bugprone-inaccurate-erase, - bugprone-incorrect-roundings, - bugprone-infinite-loop, -bugprone-integer-division, - bugprone-lambda-function-name, - bugprone-macro-parentheses, - bugprone-macro-repeated-side-effects, - bugprone-misplaced-operator-in-strlen-in-alloc, - bugprone-misplaced-pointer-arithmetic-in-alloc, - bugprone-misplaced-widening-cast, - bugprone-move-forwarding-reference, - bugprone-multiple-statement-macro, + -bugprone-multi-level-implicit-pointer-conversion, -bugprone-narrowing-conversions,, - bugprone-no-escape, - bugprone-not-null-terminated-result, - bugprone-parent-virtual-call, - bugprone-posix-return, - bugprone-redundant-branch-condition, -bugprone-reserved-identifier, - bugprone-shared-ptr-array-mismatch, - bugprone-signal-handler, -bugprone-signed-char-misuse, - bugprone-sizeof-container, -bugprone-sizeof-expression, - bugprone-spuriously-wake-up-functions, - bugprone-standalone-empty, - bugprone-string-constructor, - bugprone-string-integer-assignment, - bugprone-string-literal-with-embedded-nul, - bugprone-stringview-nullptr, - bugprone-suspicious-enum-usage, -bugprone-suspicious-include, - bugprone-suspicious-memory-comparison, - bugprone-suspicious-memset-usage, - bugprone-suspicious-missing-comma, - bugprone-suspicious-realloc-usage, - bugprone-suspicious-semicolon, - bugprone-suspicious-string-compare, - bugprone-swapped-arguments, - bugprone-terminating-continue, - bugprone-throw-keyword-missing, - bugprone-too-small-loop-variable, - bugprone-unchecked-optional-access, - bugprone-undefined-memory-manipulation, - bugprone-undelegated-constructor, - bugprone-unhandled-exception-at-new, - bugprone-unhandled-self-assignment, - bugprone-unused-raii, - bugprone-unused-return-value, - bugprone-use-after-move, - bugprone-virtual-near-miss, clang-diagnostic-shadow-field, - misc-confusable-identifiers, + misc-*, -misc-const-correctness, -misc-definitions-in-headers, - misc-misleading-bidirectional, - misc-misleading-identifier, - misc-misplaced-const, - misc-new-delete-overloads, + -misc-include-cleaner, -misc-no-recursion, - misc-non-copyable-objects, -misc-non-private-member-variables-in-classes, - misc-redundant-expression, - misc-static-assert, - misc-throw-by-value-catch-by-reference, -misc-unconventional-assign-operator, - misc-uniqueptr-reset-release, - misc-unused-alias-decls, -misc-unused-parameters, - misc-unused-using-decls, - misc-use-anonymous-namespace, + -misc-use-internal-linkage, # keep-sorted end ...