c++ - clang-8 中的自定义 clang 静态分析器检查器
问题描述
我正在尝试使用下面给出的示例在 clang 中编写一个自定义分析器:
https://clang-analyzer.llvm.org/checker_dev_manual.html
在上面的教程中,它指定在 checkers.td 中添加以下内容:
let ParentPackage = UnixAlpha in {
...
def SimpleFunc : Checker<"SimpleFunc">,
HelpText<"Check for misuses of stream APIs">,
DescFile<"SimpleFunc.cpp">;
...
} // end "alpha.unix"
我已经这样做了,我尝试再次构建 clang,但不幸的是,它返回一个错误为“找不到类 DescFile”
所以我自己在 checkers.td 中环顾四周,没有其他检查者有 DescFile 指定他们有所谓的文档(可能是版本问题?)
所以我将其更改为具有值 HasAlphaDocumentation 的文档并尝试再次构建,但现在它无法构建并返回对 clang::ento::registerSimpleFunc(CheckerManager &) 的未定义引用
下面是我的 SimpleFunc.cpp 文件的样子:
#include "ClangSACheckers.h"
#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
#include "clang/StaticAnalyzer/Core/Checker.h"
#include "clang/StaticAnalyzer/Core/CheckerManager.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
using namespace clang ;
using namespace ento ;
namespace {
class SimpleFunc : public Checker < check :: PreCall > {
mutable std :: unique_ptr < BugType > BT ;
public :
void checkPreCall ( const CallEvent & Call , CheckerContext & C ) const ;
};
}
void SimpleFunc :: 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 Report = llvm :: make_unique < BugReport >(* BT , BT - > getName () , N );
C.emitReport ( std :: move ( Report ));
}
}
void ento :: registerSimpleFunc (CheckerManager & Mgr ) {
Mgr.registerChecker<SimpleFunc>();
}
解决方案
推荐阅读
- python - 有没有办法在 Google Cloud Function 上创建 Python 脚本,将文件从存储桶下载到本地计算机?
- html - 如何禁用我的 HTML 类的 Visual Studio Code 自动修剪空白?
- authentication - PWA 的 API 身份验证
- hadoop - hadoop 集群中的 Namenode 以及 fsimage 和 Edit_logs 概念
- javascript - Firestore 将字段批量添加到数组
- laravel - Laravel - 如何为编辑视图刀片创建分层下拉列表
- javascript - 如何使用 javascript 在日历中管理 30 天和 2 月的月份
- java - POI 的 getCellNum 方法的替代方案
- machine-learning - GAN 生成器产生可区分的输出
- c# - SMO SqlBackup 期间的“等待操作超时” - 如何防止这种情况?