How to add a new clang-tidy module

Hi, all,

  I am planning to add clang-tidy checkers for my company. How to add a new module for my company? Please help, thanks in advance.

  I try to copy files from cert module, and rename cert to Misra, then add a rule named "m-0-1-1" by ./

  then I run ninja check-clang-tool, but my case is failed due to below error

  Running ['clang-tidy', '/Users/zyg/Documents/workspace/llvm-project/llvm/cmake-build-debug/tools/clang/tools/extra/test/clang-tidy/checkers/Output/misra-m-0-1-1.cpp.tmp.cpp', '-fix', '--checks=-*,misra-m-0-1-1', '-format-style=none', '--', '-std=c++11', '-nostdinc++']... clang-tidy failed: Error: no checks enabled. USAGE: clang-tidy [options] <source0> [... <sourceN>]

Below is my diff

diff --git a/clang-tools-extra/clang-tidy/CMakeLists.txt b/clang-tools-extra/clang-tidy/CMakeLists.txt
index ca7a5afed6b..ccb77ef6a62 100644
--- a/clang-tools-extra/clang-tidy/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/CMakeLists.txt
@@ -64,6 +64,7 @@ add_subdirectory(linuxkernel)
@@ -90,6 +91,7 @@ set(ALL_CLANG_TIDY_CHECKS
+ clangTidyMISRAModule
diff --git a/clang-tools-extra/clang-tidy/misra/CMakeLists.txt b/clang-tools-extra/clang-tidy/misra/CMakeLists.txt
new file mode 100644
index 00000000000..ca345a946c9
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/misra/CMakeLists.txt
@@ -0,0 +1,28 @@
+ support
+ FrontendOpenMP
+ )

See for modern example of minimal scaffolding.


Hi, Roman,

Thanks a lot, root cause should be like below. I am not familiar with this linker magic, :frowning:

Hi, Roman,

  Thanks a lot, I have resolved this issue.

diff --git a/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h b/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
index 3a5330c85c3..d9a5b486d6e 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
+++ b/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
@@ -90,6 +90,11 @@ extern volatile int MiscModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED MiscModuleAnchorDestination =

+// This anchor is used to force the linker to link the MISRAModule.
+extern volatile int MISRAModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED MISRAModuleAnchorDestination =
+ MISRAModuleAnchorSource;