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

Enable the misc-use-anonymous-namespace clang-tidy check #7661

Merged
merged 18 commits into from
Jun 24, 2023
Merged
Show file tree
Hide file tree
Changes from 17 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
156 changes: 146 additions & 10 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -4,56 +4,192 @@
---
Checks: >
-*,
bugprone-*,

# For reasons that aren't clear, clang-tidy-16 will apparently
# ignore disable-check requests if they were already enabled
# by a glob, so we will individually enumerate all the ones we want (or don't want).
# bugprone-*,
bugprone-argument-comment,
bugprone-assert-side-effect,
-bugprone-assignment-in-if-condition,
bugprone-bad-signal-to-kill-thread,
bugprone-bool-pointer-implicit-conversion,
-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-narrowing-conversions,
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-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-*,

misc-confusable-identifiers,
-misc-const-correctness,
misc-definitions-in-headers,
misc-misleading-bidirectional,
misc-misleading-identifier,
misc-misplaced-const,
misc-new-delete-overloads,
-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,

-modernize-avoid-bind,
-modernize-avoid-c-arrays,
-modernize-concat-nested-namespaces,
modernize-deprecated-headers,
modernize-loop-convert,
-modernize-deprecated-ios-base-aliases,
-modernize-loop-convert,
-modernize-macro-to-enum,
modernize-make-shared,
modernize-make-unique,
-modernize-pass-by-value,
-modernize-raw-string-literal,
modernize-redundant-void-arg,
-modernize-replace-auto-ptr,
-modernize-replace-disallow-copy-and-assign-macro,
-modernize-replace-random-shuffle,
-modernize-return-braced-init-list,
-modernize-shrink-to-fit,
-modernize-unary-static-assert,
-modernize-use-auto,
modernize-use-bool-literals,
# Disabled: there is not consensus on whether the Clang-14 behavior
# of this checker is always desirable or not, and there isn't currently
# a way to revert to the Clang-13 behavior. We may revisit this
# check the next time we examine clang-tidy options.
# modernize-use-default-member-init,
# TODO: revisit this
-modernize-use-default-member-init,
modernize-use-emplace,
modernize-use-equals-default,
modernize-use-equals-delete,
-modernize-use-nodiscard,
-modernize-use-noexcept,
modernize-use-nullptr,
modernize-use-override,
performance-*,
-modernize-use-trailing-return-type,
-modernize-use-transparent-functors,
-modernize-use-uncaught-exceptions,
-modernize-use-using

performance-faster-string-find,
performance-for-range-copy,
performance-implicit-conversion-in-loop,
performance-inefficient-algorithm,
-performance-inefficient-string-concatenation,
-performance-inefficient-vector-operation,
performance-move-const-arg,
performance-move-constructor-init,
performance-no-automatic-move,
-performance-no-int-to-ptr,
performance-noexcept-move-constructor,
performance-trivially-destructible,
performance-type-promotion-in-math-fn,
performance-unnecessary-copy-initialization,
performance-unnecessary-value-param,

readability-avoid-const-params-in-decls,
readability-braces-around-statements,
readability-const-return-type,
-readability-container-contains,
-readability-container-data-pointer,
readability-container-size-empty,
-readability-convert-member-functions-to-static,
-readability-delete-null-pointer,
-readability-duplicate-include,
-readability-else-after-return,
-readability-function-cognitive-complexity,
-readability-function-size,
-readability-identifier-length,
-readability-identifier-naming,
-readability-implicit-bool-conversion,
-readability-inconsistent-declaration-parameter-name,
-readability-isolate-declaration,
-readability-magic-numbers,
-readability-make-member-function-const,
-readability-misleading-indentation,
readability-misplaced-array-index,
-readability-named-parameter,
-readability-non-const-parameter,
readability-qualified-auto,
readability-redundant-access-specifiers,
readability-redundant-control-flow,
-readability-redundant-declaration,
readability-redundant-function-ptr-dereference,
-readability-redundant-member-init,
readability-redundant-preprocessor,
readability-redundant-smartptr-get,
readability-redundant-string-cstr,
-readability-redundant-string-init,
-readability-simplify-boolean-expr,
readability-simplify-subscript-expr,
readability-static-accessed-through-instance,
readability-static-definition-in-anonymous-namespace,
-readability-string-compare,
-readability-suspicious-call-argument,
-readability-uniqueptr-delete-release,
-readability-uppercase-literal-suffix,
-readability-use-anyofallof,

WarningsAsErrors: '*'
HeaderFilterRegex: '.*'
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ jobs:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- uses: DoozyX/clang-format-lint-action@v0.14
- uses: DoozyX/clang-format-lint-action@v0.16.2
with:
source: '.'
extensions: 'h,c,cpp'
clangFormatVersion: 14
clangFormatVersion: 16
check_clang_tidy:
name: Check clang-tidy
runs-on: ubuntu-20.04
Expand All @@ -33,14 +33,14 @@ jobs:
# from apt.llvm.org
# wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 15CF4D18AF4F7421
sudo apt-add-repository "deb https://apt.llvm.org/$(lsb_release -sc)/ llvm-toolchain-$(lsb_release -sc)-14 main"
sudo apt-add-repository "deb https://apt.llvm.org/$(lsb_release -sc)/ llvm-toolchain-$(lsb_release -sc)-16 main"
sudo apt-get update
sudo apt-get install llvm-14 clang-14 liblld-14-dev libclang-14-dev clang-tidy-14 ninja-build
sudo apt-get install llvm-16 clang-16 liblld-16-dev libclang-16-dev clang-tidy-16 ninja-build
- name: Run clang-tidy
run: |
export CC=clang-14
export CXX=clang++-14
export CLANG_TIDY_LLVM_INSTALL_DIR=/usr/lib/llvm-14
export CC=clang-16
export CXX=clang++-16
export CLANG_TIDY_LLVM_INSTALL_DIR=/usr/lib/llvm-16
./run-clang-tidy.sh
check_cmake_file_lists:
name: Check CMake file lists
Expand Down
2 changes: 1 addition & 1 deletion apps/hannk/halide/elementwise_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class Elementwise : public Generator<Elementwise> {
GeneratorParam<Type> output3_type_{"output3_type", Int(0)};

// An array of inputs.
Input<Buffer<void, 2>[]> inputs_ { "inputs" };
Input<Buffer<void, 2>[]> inputs_{"inputs"};
// The program to run. See elementwise_program.h for a description of
// this buffer.
Input<Buffer<int16_t, 2>> program_{"program"};
Expand Down
6 changes: 3 additions & 3 deletions python_bindings/src/halide/halide_/PyHalide.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ Expr double_to_expr_check(double v) {
std::vector<Expr> collect_print_args(const py::args &args) {
std::vector<Expr> v;
v.reserve(args.size());
for (size_t i = 0; i < args.size(); ++i) {
for (const auto &arg : args) {
// No way to see if a cast will work: just have to try
// and fail. Normally we don't want string to be convertible
// to Expr, but in this unusual case we do.
try {
v.emplace_back(args[i].cast<std::string>());
v.emplace_back(arg.cast<std::string>());
} catch (...) {
v.push_back(args[i].cast<Expr>());
v.push_back(arg.cast<Expr>());
}
}
return v;
Expand Down
12 changes: 6 additions & 6 deletions run-clang-format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ set -e

ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

# We are currently standardized on using LLVM/Clang14 for this script.
# We are currently standardized on using LLVM/Clang16 for this script.
# Note that this is totally independent of the version of LLVM that you
# are using to build Halide itself. If you don't have LLVM14 installed,
# you can usually install what you need easily via:
#
# sudo apt-get install llvm-14 clang-14 libclang-14-dev clang-tidy-14
# export CLANG_FORMAT_LLVM_INSTALL_DIR=/usr/lib/llvm-14
# sudo apt-get install llvm-16 clang-14 libclang-16-dev clang-tidy-16
# export CLANG_FORMAT_LLVM_INSTALL_DIR=/usr/lib/llvm-16

[ -z "$CLANG_FORMAT_LLVM_INSTALL_DIR" ] && echo "CLANG_FORMAT_LLVM_INSTALL_DIR must point to an LLVM installation dir for this script." && exit
echo CLANG_FORMAT_LLVM_INSTALL_DIR = ${CLANG_FORMAT_LLVM_INSTALL_DIR}

VERSION=$(${CLANG_FORMAT_LLVM_INSTALL_DIR}/bin/clang-format --version)
if [[ ${VERSION} =~ .*version\ 14.* ]]
if [[ ${VERSION} =~ .*version\ 16.* ]]
then
echo "clang-format version 14 found."
echo "clang-format version 16 found."
else
echo "CLANG_FORMAT_LLVM_INSTALL_DIR must point to an LLVM 14 install!"
echo "CLANG_FORMAT_LLVM_INSTALL_DIR must point to an LLVM 16 install!"
exit 1
fi

Expand Down
15 changes: 8 additions & 7 deletions run-clang-tidy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

FIX=$1

# We are currently standardized on using LLVM/Clang14 for this script.
# We are currently standardized on using LLVM/Clang16 for this script.
# Note that this is totally independent of the version of LLVM that you
# are using to build Halide itself. If you don't have LLVM14 installed,
# you can usually install what you need easily via:
#
# sudo apt-get install llvm-14 clang-14 libclang-14-dev clang-tidy-14
# export CLANG_TIDY_LLVM_INSTALL_DIR=/usr/lib/llvm-14
# sudo apt-get install llvm-16 clang-14 libclang-16-dev clang-tidy-16
# export CLANG_TIDY_LLVM_INSTALL_DIR=/usr/lib/llvm-16

[ -z "$CLANG_TIDY_LLVM_INSTALL_DIR" ] && echo "CLANG_TIDY_LLVM_INSTALL_DIR must point to an LLVM installation dir for this script." && exit
echo CLANG_TIDY_LLVM_INSTALL_DIR = ${CLANG_TIDY_LLVM_INSTALL_DIR}

VERSION=$(${CLANG_TIDY_LLVM_INSTALL_DIR}/bin/clang-tidy --version)
if [[ ${VERSION} =~ .*version\ 14.* ]]
if [[ ${VERSION} =~ .*version\ 16.* ]]
then
echo "clang-tidy version 14 found."
echo "clang-tidy version 16 found."
else
echo "CLANG_TIDY_LLVM_INSTALL_DIR must point to an LLVM 14 install!"
echo "CLANG_TIDY_LLVM_INSTALL_DIR must point to an LLVM 16 install!"
exit 1
fi

Expand Down Expand Up @@ -62,7 +62,7 @@ CLANG_TIDY_TARGETS=$(find \
"${ROOT_DIR}/python_bindings" \
"${ROOT_DIR}/tools" \
"${ROOT_DIR}/util" \
\( -name *.cpp -o -name *.h -o -name *.c \) -and -not -wholename "*/.*" \
\( -name "*.cpp" -o -name "*.h" -o -name "*.c" \) -and -not -wholename "*/.*" \
! -name DefaultCostModel.cpp \
! -name GenGen.cpp \
! -name RunGenMain.cpp)
Expand All @@ -73,6 +73,7 @@ CLANG_TIDY_HEADER_FILTER=".*/src/.*|.*/python_bindings/.*|.*/tools/.*|.*/util/.*

${RUN_CLANG_TIDY} \
${FIX} \
-j $(nproc) \
-header-filter="${CLANG_TIDY_HEADER_FILTER}" \
-quiet \
-p ${CLANG_TIDY_BUILD_DIR} \
Expand Down
Loading