<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/58012>58012</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
我在测试自己编写的插件时显示让我写issues报告bug
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
wz-fu
</td>
</tr>
</table>
<pre>
bug信息:
> ![image-20220927155543203](https://raw.githubusercontent.com/wz-fu/My-img/master/img/image-20220927155543203.png)
>
> ![image-20220927155703589](https://raw.githubusercontent.com/wz-fu/My-img/master/img/image-20220927155703589.png)
>
> ![image-20220927155812768](https://raw.githubusercontent.com/wz-fu/My-img/master/img/image-20220927155812768.png)
clang版本:16.0.0
命令:
> ./bin/clang -cc1 -load ./lib/FunPramCheckerPlugin.so -analyze -analyzer-checker=plugin.FunPramChecker ~/ShiXi/Example_Test.c -I /usr/include/ -I ~/llvm-project/build/lib/clang/16.0.0/include/
测试文件:
~~~c
#include "stdio.h"
typedef int (*main_t)(int, char **);
int main(int argc, char **argv)
{
main_t foo = main;
int exit_code = foo(argc, argv); // actually calls main()!
return exit_code;
}
~~~
插件文件:
~~~c++
#include <iostream>
#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
#include "clang/StaticAnalyzer/Core/Checker.h"
#include "clang/StaticAnalyzer/Frontend/CheckerRegistry.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
#include "clang/Basic/LLVM.h"
#include "llvm/Object/ObjectFile.h"
using namespace clang;
using namespace ento;
using namespace std;
namespace
{
class FunPramChecker : public Checker<check::PreCall>
{
public:
mutable std::unique_ptr<BuiltinBug> BT;
public:
void checkPreCall(const CallEvent &Call, CheckerContext &Ctx) const;
};
} // anonymous namespace
void FunPramChecker::checkPreCall(const CallEvent &Call, CheckerContext &Ctx) const
{
unsigned PramNum = Call.getNumArgs();
const FunctionDecl *Pramarg = Call.getArgSVal(0).getAsFunctionDecl();
string name = Pramarg->getNameInfo().getAsString();
cout << name << endl;
}
// Register plugin!
extern "C" void clang_registerCheckers(CheckerRegistry ®istry)
{
registry.addChecker<FunPramChecker>(
"plugin.FunPramChecker", "The parameter of the function is illegal",
"");
}
extern "C" const char clang_analyzerAPIVersionString[] =
CLANG_ANALYZER_API_VERSION_STRING;
~~~
CMakeLists.txt
~~~cmake
set(LLVM_LINK_COMPONENTS
Support
)
set(LLVM_EXPORTED_SYMBOL_FILE ${CMAKE_CURRENT_SOURCE_DIR}/FunPramCheckerPlugin.exports)
add_llvm_library(FunPramCheckerPlugin MODULE BUILDTREE_ONLY FunPramChecker.cpp PLUGIN_TOOL clang)
clang_target_link_libraries(FunPramCheckerPlugin PRIVATE
clangAnalysis
clangAST
clangStaticAnalyzerCore
clangStaticAnalyzerFrontend
)
~~~
FunPramCheckerPlugin.exports:
~~~
clang_registerCheckers
clang_analyzerAPIVersionString
~~~
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy1V92TojgQ_2viS0oLQRQefADELWsdtdSZ2rkXKkJGc4vgQZid2b_-usOH4uhuzdXtFIMhSXf_0t_ZpdH7eFfsiT8g7pQ4feIPidUnzpT4U-J6xHaINiFa_TZ8SvQ-MV1xZHve1TVd12x91DdNc2DomkHMCdGtg5SnnBgO0afwZOxHby_kodgVOc_CNJE8kb0wPcLaj5_dlwJ-H9674riHwZHlkmcwKD_viOmdEli1G1C_RTfSDNOy_zi6Usyn0Vl9fTS0_ji6UkwbnXqHMYM5f0RARZaFLmB7xPEaF-gPe1pPazmCbxK7T9yJchyXOIO7_tIDKDuRwFuJod0w7NNunLJILcViB-9pkawydvQOPPzOs1Vc7EXSy1PaZQmL33_yZpB1w3IPMSanclublpKRDww3B_FNwK__xo6nmAdbnoPeaHcGNpgWudJSEsZFxGGkphVZHL8eu6cs_ZuHEnEXIo4akKWa9GmljksObd0MiWsSyyW-hYFkm0qjEFejSlvu8La2AIJ6wupbNy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