From 8da7efbb0d5ec315a27b7b5286dbdd25694905ad Mon Sep 17 00:00:00 2001 From: Vasily Kulikov Date: Mon, 30 Nov 2020 12:15:01 +0300 Subject: [PATCH] [clang-tidy] add concurrency module The module will contain checks related to concurrent programming (including threads, fibers, coroutines, etc.). Reviewed By: lebedev.ri Differential Revision: https://reviews.llvm.org/D91656 --- clang-tools-extra/clang-tidy/CMakeLists.txt | 2 ++ .../clang-tidy/ClangTidyForceLinker.h | 5 ++++ .../clang-tidy/concurrency/CMakeLists.txt | 22 +++++++++++++++ .../concurrency/ConcurrencyTidyModule.cpp | 33 ++++++++++++++++++++++ clang-tools-extra/docs/ReleaseNotes.rst | 5 ++++ clang-tools-extra/docs/clang-tidy/index.rst | 2 ++ 6 files changed, 69 insertions(+) create mode 100644 clang-tools-extra/clang-tidy/concurrency/CMakeLists.txt create mode 100644 clang-tools-extra/clang-tidy/concurrency/ConcurrencyTidyModule.cpp diff --git a/clang-tools-extra/clang-tidy/CMakeLists.txt b/clang-tools-extra/clang-tidy/CMakeLists.txt index ca7a5afe..4556450 100644 --- a/clang-tools-extra/clang-tidy/CMakeLists.txt +++ b/clang-tools-extra/clang-tidy/CMakeLists.txt @@ -55,6 +55,7 @@ add_subdirectory(altera) add_subdirectory(boost) add_subdirectory(bugprone) add_subdirectory(cert) +add_subdirectory(concurrency) add_subdirectory(cppcoreguidelines) add_subdirectory(darwin) add_subdirectory(fuchsia) @@ -81,6 +82,7 @@ set(ALL_CLANG_TIDY_CHECKS clangTidyBoostModule clangTidyBugproneModule clangTidyCERTModule + clangTidyConcurrencyModule clangTidyCppCoreGuidelinesModule clangTidyDarwinModule clangTidyFuchsiaModule diff --git a/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h b/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h index 3a5330c..2691d90 100644 --- a/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h +++ b/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h @@ -45,6 +45,11 @@ extern volatile int CERTModuleAnchorSource; static int LLVM_ATTRIBUTE_UNUSED CERTModuleAnchorDestination = CERTModuleAnchorSource; +// This anchor is used to force the linker to link the ConcurrencyModule. +extern volatile int ConcurrencyModuleAnchorSource; +static int LLVM_ATTRIBUTE_UNUSED ConcurrencyModuleAnchorDestination = + ConcurrencyModuleAnchorSource; + // This anchor is used to force the linker to link the CppCoreGuidelinesModule. extern volatile int CppCoreGuidelinesModuleAnchorSource; static int LLVM_ATTRIBUTE_UNUSED CppCoreGuidelinesModuleAnchorDestination = diff --git a/clang-tools-extra/clang-tidy/concurrency/CMakeLists.txt b/clang-tools-extra/clang-tidy/concurrency/CMakeLists.txt new file mode 100644 index 0000000..e09de74 --- /dev/null +++ b/clang-tools-extra/clang-tidy/concurrency/CMakeLists.txt @@ -0,0 +1,22 @@ +set(LLVM_LINK_COMPONENTS + Support + ) + +add_clang_library(clangTidyConcurrencyModule + ConcurrencyTidyModule.cpp + + LINK_LIBS + clangTidy + clangTidyUtils + ) + +clang_target_link_libraries(clangTidyConcurrencyModule + PRIVATE + clangAnalysis + clangAST + clangASTMatchers + clangBasic + clangLex + clangSerialization + clangTooling + ) diff --git a/clang-tools-extra/clang-tidy/concurrency/ConcurrencyTidyModule.cpp b/clang-tools-extra/clang-tidy/concurrency/ConcurrencyTidyModule.cpp new file mode 100644 index 0000000..be8fa7e --- /dev/null +++ b/clang-tools-extra/clang-tidy/concurrency/ConcurrencyTidyModule.cpp @@ -0,0 +1,33 @@ +//===--- ConcurrencyTidyModule.cpp - clang-tidy ---------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "../ClangTidy.h" +#include "../ClangTidyModule.h" +#include "../ClangTidyModuleRegistry.h" + +namespace clang { +namespace tidy { +namespace concurrency { + +class ConcurrencyModule : public ClangTidyModule { +public: + void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {} +}; + +} // namespace concurrency + +// Register the ConcurrencyTidyModule using this statically initialized variable. +static ClangTidyModuleRegistry::Add + X("concurrency-module", "Adds concurrency checks."); + +// This anchor is used to force the linker to link in the generated object file +// and thus register the ConcurrencyModule. +volatile int ConcurrencyModuleAnchorSource = 0; + +} // namespace tidy +} // namespace clang diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 46bb36c..46461a2 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -82,6 +82,11 @@ New modules `Altera SDK for OpenCL: Best Practices Guide `_. +- New ``concurrency`` module. + + Includes checks related to concurrent programming (e.g. threads, fibers, + coroutines, etc.). + New checks ^^^^^^^^^^ diff --git a/clang-tools-extra/docs/clang-tidy/index.rst b/clang-tools-extra/docs/clang-tidy/index.rst index a85c721..b8af4d3 100644 --- a/clang-tools-extra/docs/clang-tidy/index.rst +++ b/clang-tools-extra/docs/clang-tidy/index.rst @@ -64,6 +64,8 @@ Name prefix Description ``bugprone-`` Checks that target bugprone code constructs. ``cert-`` Checks related to CERT Secure Coding Guidelines. ``clang-analyzer-`` Clang Static Analyzer checks. +``concurrency-`` Checks related to concurrent programming (including + threads, fibers, coroutines, etc.). ``cppcoreguidelines-`` Checks related to C++ Core Guidelines. ``darwin-`` Checks related to Darwin coding conventions. ``fuchsia-`` Checks related to Fuchsia coding conventions. -- 2.7.4