我正在尝试将自己的检查器添加到clang's static analyzer。在instructions for adding a checker to clang之后,我做了以下事情:
在MyChecker.cpp
中编写骨架检查器:
using namespace clang;
using namespace ento;
namespace {
class MyChecker : public Checker<check::PreCall,
check::PostCall,
check::Location> {
public:
void checkPreCall(const CallEvent &Call, CheckerContext &C) const;
void checkPostCall(const CallEvent &Call, CheckerContext &C) const;
};
}
void MyChecker::checkPreCall(const CallEvent &Call, CheckerContext &C) const {}
void MyChecker::checkPostCall(const CallEvent &Call, CheckerContext &C) const {}
void ento::registerMyChecker(CheckerManager &mgr) {
mgr.registerChecker<MyChecker>();
}
将源文件添加到Checkers CMakeLists.txt
文件中:
...
MPI-Checker/MPIFunctionClassifier.cpp
MyChecker.cpp
NSAutoreleasePoolChecker.cpp
...
并在Checkers.td
添加了一个条目:
def MyChecker : Checker<"MyChecker">,
HelpText<"MyChecker">,
DescFile<"MyChecker.cpp">;
当我尝试编译clang时,我收到以下错误:
MyChecker.cpp:30:12: error: out-of-line definition of 'registerMyChecker' does not match any declaration in namespace 'clang::ento'
void ento::registerMyChecker(CheckerManager &mgr) {
^~~~~~~~~~~~~~~~~
1 error generated.
ninja: build stopped: subcommand failed.
为什么我无法注册MyChecker?
答案 0 :(得分:1)
因此,clang static checkers注册依赖于包含静态检查器注册函数的生成声明的文件 - ClangSACheckers.h
。静态检查器源文件应包含该头文件并实现注册函数void ento::registerMyChecker(CheckerManager &mgr)