Skip to content

Commit 6ced34d

Browse files
vtjnashvchuravy
authored andcommitted
enable plugins for clang-tidy
Fixes https://bugs.llvm.org//show_bug.cgi?id=32739, so pinging people who previously discussed that issue. This takes advantage of the existing plugin capabilities of llvm to add support for `-load` simply by requesting adding the header file to request it. I've tested out-of-tree something of this form (leaving out a few details of the check logic itself), and confirmed that it seems to load and get called with this patch: ``` #include "clang/AST/ASTContext.h" #include "clang/ASTMatchers/ASTMatchFinder.h" #include "clang-tidy/ClangTidy.h" #include "clang-tidy/ClangTidyCheck.h" #include "clang-tidy/ClangTidyModule.h" #include "clang-tidy/ClangTidyModuleRegistry.h" using namespace clang; using namespace clang::tidy; using namespace clang::ast_matchers; class MyTestCheck : public ClangTidyCheck; namespace { class CTTestModule : public ClangTidyModule { public: void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override { CheckFactories.registerCheck<MyTestCheck>("mytest"); } }; } // namespace namespace clang { namespace tidy { // Register the CTTestTidyModule using this statically initialized variable. static ClangTidyModuleRegistry::Add<::CTTestModule> X("mytest-module", "Adds my checks."); // This anchor is used to force the linker to link in the generated object file // and thus register the CTTestModule. volatile int CTTestModuleAnchorSource = 0; } // namespace tidy } // namespace clang ``` ``` $ ./bin/clang-tidy --checks=-*,mytest -list-checks -load mytestcheckplugin.so Enabled checks: mytest ``` Differential Revision: https://reviews.llvm.org/D111100
1 parent 37f68c7 commit 6ced34d

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

clang-tools-extra/clang-tidy/tool/CMakeLists.txt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,17 @@ clang_target_link_libraries(clangTidyMain
2929
clangToolingCore
3030
)
3131

32+
# Support plugins.
33+
if(CLANG_PLUGIN_SUPPORT)
34+
set(support_plugins SUPPORT_PLUGINS)
35+
endif()
36+
3237
add_clang_tool(clang-tidy
3338
ClangTidyToolMain.cpp
34-
)
35-
add_dependencies(clang-tidy
39+
40+
DEPENDS
3641
clang-resource-headers
42+
${support_plugins}
3743
)
3844
clang_target_link_libraries(clang-tidy
3945
PRIVATE
@@ -50,6 +56,9 @@ target_link_libraries(clang-tidy
5056
${ALL_CLANG_TIDY_CHECKS}
5157
)
5258

59+
if(CLANG_PLUGIN_SUPPORT)
60+
export_executable_symbols_for_plugins(clang-tidy)
61+
endif()
5362

5463
install(PROGRAMS clang-tidy-diff.py
5564
DESTINATION share/clang

clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "../GlobList.h"
2121
#include "clang/Tooling/CommonOptionsParser.h"
2222
#include "llvm/Support/InitLLVM.h"
23+
#include "llvm/Support/PluginLoader.h"
2324
#include "llvm/Support/Process.h"
2425
#include "llvm/Support/Signals.h"
2526
#include "llvm/Support/TargetSelect.h"

0 commit comments

Comments
 (0)