Skip to content

Commit

Permalink
feat: add clang-tidy for pika (OpenAtomFoundation#1515)
Browse files Browse the repository at this point in the history
* feature:add clang-tidy for pika

There are several conflicting files left that need to be manually modified. See run_clang_tidy.py.And disabled some clang-tidy checks, eg, use int64_t instead of long or long long, variable naming.

Signed-off-by: Hao Lee <[email protected]>

* feature:WIP modified clang-tidy file

Signed-off-by: Hao Lee <[email protected]>

* feature:disable compile command clang-tidy check

Signed-off-by: Hao Lee <[email protected]>

* style:Make the code standard according to clang-tidy

Signed-off-by: Hao Lee <[email protected]>

* delete double std::move

* auto* -> auto

* using noncopyable

* add space for override{}

* add spaces

* delete != 0

* format if-return

* clear inheritage

* format codes

* format codes

* delete == 0

* fix:fix build error

Signed-off-by: Hao Lee <[email protected]>

* style:disable check bool implicit convert in clang-tidy

Signed-off-by: Hao Lee <[email protected]>

* style:update code style

Signed-off-by: Hao Lee <[email protected]>

* delete '!= nullptr'

* format if/while

* fix ci failure

* fix:build ci error

Signed-off-by: Hao Lee <[email protected]>

* style:The judgment statement should not be an assignment

Signed-off-by: Hao Lee <[email protected]>

* style:format codes

remove redundant extern statement and use default

Signed-off-by: Hao Lee <[email protected]>

* style:format codes

remove redundant extern g_pika_conf statement and correct if statement judgement instead of assignment

Signed-off-by: Hao Lee <[email protected]>

* format codes

* format codes

---------

Signed-off-by: Hao Lee <[email protected]>
Co-authored-by: alexstocks <[email protected]>
Co-authored-by: Xin.Zh <[email protected]>
  • Loading branch information
3 people authored May 27, 2023
1 parent 22bd428 commit 83cad14
Show file tree
Hide file tree
Showing 253 changed files with 6,309 additions and 5,349 deletions.
118 changes: 118 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
---
Checks: '
bugprone-*,
clang-analyzer-*,
google-*,
modernize-*,
performance-*,
portability-*,
readability-*,
-bugprone-easily-swappable-parameters,
-bugprone-implicit-widening-of-multiplication-result,
-bugprone-narrowing-conversions,
-bugprone-reserved-identifier,
-bugprone-signed-char-misuse,
-bugprone-suspicious-include,
-bugprone-unhandled-self-assignment,
-clang-analyzer-cplusplus.NewDelete,
-clang-analyzer-cplusplus.NewDeleteLeaks,
-clang-analyzer-security.insecureAPI.rand,
-clang-diagnostic-implicit-int-float-conversion,
-google-readability-avoid-underscore-in-googletest-name,
-modernize-avoid-c-arrays,
-modernize-use-nodiscard,
-readability-convert-member-functions-to-static,
-readability-identifier-length,
-readability-function-cognitive-complexity,
-readability-magic-numbers,
-readability-make-member-function-const,
-readability-qualified-auto,
-readability-redundant-access-specifiers,
-bugprone-exception-escape,
-modernize-use-trailing-return-type,
-readability-function-size,
-readability-else-after-return,
-bugprone-branch-clone,
-readability-use-anyofallof,
-google-default-arguments,
-clang-analyzer-cplusplus.InnerPointer,
-google-explicit-constructor,
-use_of_tag_name_without_tag,
-clang-analyzer-core.CallAndMessage,
-clang-analyzer-deadcode.DeadStores,
-google-runtime-int,
-clang-diagnostic-unused-command-line-argument,
-clang-diagnostic-ignored-optimization-argument,
-readability-implicit-bool-conversion,
'
# CheckOptions:
# - { key: readability-identifier-naming.ClassCase, value: CamelCase }
# - { key: readability-identifier-naming.EnumCase, value: CamelCase }
# - { key: readability-identifier-naming.FunctionCase, value: CamelCase }
# - { key: readability-identifier-naming.GlobalConstantCase, value: UPPER_CASE }
# - { key: readability-identifier-naming.MemberCase, value: lower_case }
# - { key: readability-identifier-naming.MemberSuffix, value: _ }
# - { key: readability-identifier-naming.NamespaceCase, value: lower_case }
# - { key: readability-identifier-naming.StructCase, value: CamelCase }
# - { key: readability-identifier-naming.UnionCase, value: CamelCase }
# - { key: readability-identifier-naming.VariableCase, value: lower_case }

WarningsAsErrors: '*'
# HeaderFilterRegex: '(|/src|/src/net|/src/pstd|/src/storage)/include'
# HeaderFilterRegex: '/src/(net|storage|pstd)/include'
AnalyzeTemporaryDtors: true

#### Disabled checks and why: #####
#
# -readability-convert-member-functions-to-static,
# This check started going off in the upgrade from clang-tidy-8 to clang-tidy-12. It is not always correct because
# we hide the reference implementation in another repository.
# -clang-analyzer-security.insecureAPI.rand, -clang-analyzer-security.insecureAPI.rand, -bugprone-unhandled-self-assignment,
# -bugprone-implicit-widening-of-multiplication-result
# These have not been investigated yet.
# -bugprone-reserved-identifier,
# Fails due to use of some __SHORT_FILE__ symbol, originating from very old code.
# -bugprone-suspicious-include,
# False positive due to GTest code.
# -bugprone-too-small-loop-variable,
# Complains about uint8_t or uint16_t when the limit on the loop is a container's .size() (size_t).
# We usually do this when we know the maximum size of the container though, so propose leaving disabled.
# -clang-analyzer-cplusplus.NewDelete,
# Seems to generate false positives. Suggest relying on ASAN and valgrind for memory stuff.
# -clang-analyzer-cplusplus.NewDeleteLeaks,
# Seems to generate false positives. Suggest relying on ASAN and valgrind for memory stuff.
# -modernize-use-nodiscard,
# New C++17 feature, slightly polarizing. Would clutter codebase.
# -modernize-avoid-c-arrays,
# Let's not deal with people doing ridiculous things to hack around this. If it bites them, it bites them.
# -bugprone-signed-char-misuse, -clang-diagnostic-implicit-int-float-conversion, -readability-make-member-function-const,
# -readability-qualified-auto, -readability-redundant-access-specifiers
# These were previously disabled for not being available in clang-tidy-8. They are now available on our clang-tidy-12,
# and potentially worth investigating/fixing.
# -bugprone-exception-escape
# Weird. No idea how to resolve.
# -bugprone-branch-clone,
# frequent misidentification
# -google-default-arguments
# Too many virtual functions in pika have default parameters, specifically void Do(std::shared_ptr<Partition> partition = nullptr)
# -clang-analyzer-cplusplus.InnerPointer
# I don't know why this bug in the RocksDB library fails to suppress detection.So I have to disable this check.
#--google-explicit-constructor
# There are so many implicit convert in pika
#--use_of_tag_name_without_tag
# like class member is class , If there is no class tag, an error will be reported
# class A{ B b_; } -> error ; class A{ class B b_; } -> no error ;
#-clang-analyzer-core.CallAndMessage
# pika/src/storage/src/scope_record_lock.h
# Always detect a null pointer and call the TryLock method
# Called C++ object pointer is null [clang-analyzer-core.CallAndMessage,-warnings-as-errors]
# lock_mgr_->UnLock(key);
#-clang-analyzer-deadcode.DeadStores
# error detection in some places
#-google-runtime-int
# todo discussed, because there are so many of `long` and `long long` in pika, so disable for now
#-clang-diagnostic-unused-command-line-argument
# because there are to many compile command error in github ci, but no error in local environment
# See in build folder compile_commands.json
#-clang-diagnostic-ignored-optimization-argument
# The reason disabled this is same as above.
2 changes: 1 addition & 1 deletion .github/workflows/pika.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,4 @@ jobs:
run: |
cd ${{github.workspace}}/build
source /opt/rh/devtoolset-10/enable
ctest -C ${{env.BUILD_TYPE}}
ctest -C ${{env.BUILD_TYPE}}
37 changes: 37 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,26 @@ if (${AUTOCONF} MATCHES AUTOCONF-NOTFOUND)
message(FATAL_ERROR "not find autoconf on localhost")
endif()

find_program(CLANG_TIDY_BIN
NAMES clang-tidy clang-tidy-12
HINTS ${CLANG_SEARCH_PATH})
if ("${CLANG_TIDY_BIN}" STREQUAL "CLANG_TIDY_BIN-NOTFOUND")
message(WARNING "couldn't find clang-tidy.")
else ()
message(STATUS "found clang-tidy at ${CLANG_TIDY_BIN}")
endif ()

find_program(CLANG_APPLY_REPLACEMENTS_BIN
NAMES clang-apply-replacements clang-apply-replacements-12
HINTS ${CLANG_SEARCH_PATH})

if ("${CLANG_APPLY_REPLACEMENTS_BIN}" STREQUAL "CLANG_APPLY_REPLACEMENTS_BIN-NOTFOUND")
message(WARNING "couldn't find clang-apply-replacements.")
else ()
message(STATUS "found clang-apply-replacements at ${CLANG_APPLY_REPLACEMENTS_BIN}")
endif ()


include(protogen.cmake)
include(ExternalProject)

Expand Down Expand Up @@ -750,3 +770,20 @@ target_link_libraries(${PROJECT_NAME}
${JEMALLOC_LIBRARY})

option(USE_SSL "Enable SSL support" OFF)
add_custom_target(
clang-tidy
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/run_clang_tidy.py
-clang-tidy-binary ${CLANG_TIDY_BIN}
-header-filter='${PROJECT_SOURCE_DIR}(/include|/tools|/src)/.*'
-p ${CMAKE_BINARY_DIR}
-quiet
)

add_custom_target(clang-tidy-fix
${CMAKE_CURRENT_SOURCE_DIR}/run_clang_tidy.py
-clang-tidy-binary ${CLANG_TIDY_BIN}
-p ${CMAKE_BINARY_DIR}
-header-filter='${PROJECT_SOURCE_DIR}(/include|/tools|/src)/.*'
-clang-apply-replacements-binary ${CLANG_APPLY_REPLACEMENTS_BIN}
-fix
)
Loading

0 comments on commit 83cad14

Please sign in to comment.