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