简体   繁体   English

如何注册我的 Clang Static 分析仪检查器

[英]How do I register my Clang Static Analyzer checker

I am fully aware that this question has previous answers.我完全知道这个问题有以前的答案。 However, those answers are old and don't reflect what is happening in the current code base.但是,这些答案是旧的,并没有反映当前代码库中发生的事情。

I have followed the steps in this guide for developing the checker, registering it with the engine, and testing it.我已按照本指南中的步骤开发检查器、将其注册到引擎并进行测试。

After some work, I was able to compile the code but when running clang -cc1 -analyzer-checker-help my checker is not visible.经过一些工作后,我能够编译代码,但是在运行clang -cc1 -analyzer-checker-help时,我的检查器不可见。 I Have noticed that a lot of the checkers aren't visible.我注意到很多跳棋是不可见的。

Do I need to explicitly enable the checker on the command line?我是否需要在命令行上显式启用检查器? If not what have I missed?如果不是,我错过了什么?

When I run clang --analyze test.cpp of clang -cc1 -analyze test.cpp my checker does not raise a warning.当我运行clang --analyze test.cpp of clang -cc1 -analyze test.cpp我的检查器没有发出警告。 But others do, even those "not visible" in the clang -cc1 -analyzer-checker-help command.但其他人会这样做,即使是clang -cc1 -analyzer-checker-help命令中“不可见”的那些。

Please do not point me into the direction of 6 year old documentation that is outdated.请不要将我指向已过时的 6 年旧文档的方向。 I want to know how to get this done.我想知道如何完成这项工作。

My code:我的代码:

MainCallChecker.cpp MainCallChecker.cpp

using namespace clang;
using namespace ento;
namespace {
class MainCallChecker : public Checker<check::PreCall> {
  mutable std::unique_ptr<BugType> BT;

public:
  void checkPreCall(const CallEvent &Call, CheckerContext &C) const;
};
}

void MainCallChecker::checkPreCall(const CallEvent &Call,
                                   CheckerContext &C) const {

  if(const IdentifierInfo *II = Call.getCalleeIdentifier()) {

    if(II ->isStr("main")) {

      if(!BT) {
        BT.reset(new BugType(this, "Call to main", "Example checker"));
        ExplodedNode *N = C.generateErrorNode();
        auto R = std::make_unique<PathSensitiveBugReport>(*BT, BT->getCheckerName(), N);
        C.emitReport(std::move(R));
      }

    }

  }

}

void ento::registerMainCallChecker(CheckerManager &mgr){
  mgr.registerChecker<MainCallChecker>();
}

Checkers.td西洋跳棋

def MainCallChecker : Checker<"MainCall">,
  HelpText<"MyChecker">,
  Documentation<NotDocumented>;

CMakeLists.txt CMakeLists.txt

add_clang_library(clangStaticAnalyzerCheckers
.
.
MainCallChecker.cpp
.
.
)

test.cpp测试.cpp

typedef int (*main_t)(int, char **);
int main(int argc, char** argv) {
        main_t foo = main;
        int exit_code = foo(argc, argv);
        return exit_code;
        
}

UPDATE: A Clang contributor provided me a helpful answer that fixed my problem.更新:一位 Clang 的贡献者为我提供了一个有用的答案,解决了我的问题。 via the llvm discorse通过llvm discorse

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM