tmroeder created this revision. Herald added subscribers: cfe-commits, jdoerfert, mgorny. Herald added a project: clang.
Now that clang is going to be able to build the Linux kernel again on x86, and we have gen_compile_commands.py upstream for generating compile_commands.json, clang-tidy can be used on the Linux kernel source. To that end, this commit adds a new clang-tidy module to be used for checks specific to Linux kernel source. The Linux kernel follows its own style of C, and it will be useful to separate those checks into their own module. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D59963 Files: clang-tools-extra/clang-tidy/CMakeLists.txt clang-tools-extra/clang-tidy/ClangTidyForceLinker.h clang-tools-extra/clang-tidy/linux/CMakeLists.txt clang-tools-extra/clang-tidy/linux/LinuxTidyModule.cpp clang-tools-extra/clang-tidy/plugin/CMakeLists.txt clang-tools-extra/clang-tidy/tool/CMakeLists.txt
Index: clang-tools-extra/clang-tidy/tool/CMakeLists.txt =================================================================== --- clang-tools-extra/clang-tidy/tool/CMakeLists.txt +++ clang-tools-extra/clang-tidy/tool/CMakeLists.txt @@ -26,6 +26,7 @@ clangTidyFuchsiaModule clangTidyGoogleModule clangTidyHICPPModule + clangTidyLinuxModule clangTidyLLVMModule clangTidyMiscModule clangTidyModernizeModule Index: clang-tools-extra/clang-tidy/plugin/CMakeLists.txt =================================================================== --- clang-tools-extra/clang-tidy/plugin/CMakeLists.txt +++ clang-tools-extra/clang-tidy/plugin/CMakeLists.txt @@ -17,6 +17,7 @@ clangTidyFuchsiaModule clangTidyGoogleModule clangTidyHICPPModule + clangTidyLinuxModule clangTidyLLVMModule clangTidyMiscModule clangTidyModernizeModule Index: clang-tools-extra/clang-tidy/linux/LinuxTidyModule.cpp =================================================================== --- /dev/null +++ clang-tools-extra/clang-tidy/linux/LinuxTidyModule.cpp @@ -0,0 +1,35 @@ +//===--- LinuxTidyModule.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" + +using namespace clang::ast_matchers; + +namespace clang { +namespace tidy { +namespace linux { + +/// This module is for Linux-kernel-specific checks. +class LinuxModule : public ClangTidyModule { +public: + void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override { + } +}; +// Register the LinuxTidyModule using this statically initialized variable. +static ClangTidyModuleRegistry::Add<LinuxModule> + X("linux-module", "Adds checks specific to the Linux kernel source."); +} // namespace linux + +// This anchor is used to force the linker to link in the generated object file +// and thus register the LinuxModule. +volatile int LinuxModuleAnchorSource = 0; + +} // namespace tidy +} // namespace clang Index: clang-tools-extra/clang-tidy/linux/CMakeLists.txt =================================================================== --- /dev/null +++ clang-tools-extra/clang-tidy/linux/CMakeLists.txt @@ -0,0 +1,13 @@ +set(LLVM_LINK_COMPONENTS support) + +add_clang_library(clangTidyLinuxModule + LinuxTidyModule.cpp + + LINK_LIBS + clangAST + clangASTMatchers + clangBasic + clangLex + clangTidy + clangTidyUtils + ) Index: clang-tools-extra/clang-tidy/ClangTidyForceLinker.h =================================================================== --- clang-tools-extra/clang-tidy/ClangTidyForceLinker.h +++ clang-tools-extra/clang-tidy/ClangTidyForceLinker.h @@ -35,6 +35,11 @@ static int LLVM_ATTRIBUTE_UNUSED BugproneModuleAnchorDestination = BugproneModuleAnchorSource; +// This anchor is used to force the linker to link the LinuxModule. +extern volatile int LinuxModuleAnchorSource; +static int LLVM_ATTRIBUTE_UNUSED LinuxModuleAnchorDestination = + LinuxModuleAnchorSource; + // This anchor is used to force the linker to link the LLVMModule. extern volatile int LLVMModuleAnchorSource; static int LLVM_ATTRIBUTE_UNUSED LLVMModuleAnchorDestination = Index: clang-tools-extra/clang-tidy/CMakeLists.txt =================================================================== --- clang-tools-extra/clang-tidy/CMakeLists.txt +++ clang-tools-extra/clang-tidy/CMakeLists.txt @@ -44,6 +44,7 @@ add_subdirectory(fuchsia) add_subdirectory(google) add_subdirectory(hicpp) +add_subdirectory(linux) add_subdirectory(llvm) add_subdirectory(misc) add_subdirectory(modernize)
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits