我最近开始使用 LLVM。我正在尝试在给定以下代码的 LLVM 中编写一个通行证
string = (char *)malloc(100);
string = NULL;
Run Code Online (Sandbox Code Playgroud)
和相应的LLVM IR
%call = call noalias i8* @malloc(i64 100) #3
store i8* %call, i8** %string, align 8
store i8* null, i8** %string, align 8
Run Code Online (Sandbox Code Playgroud)
检测指令调用malloc,提取number of bytes分配的(在本例中为 100),address返回的地址和分配给的变量名称。
std::map<std::string, std::tuple<size_t, int> > mem_addrs; // stores pointer name, address and no. of bytes allocated
Count() : ModulePass(ID) {}
virtual bool runOnModule(Module &M) {
for (Function &F: M) {
for (BasicBlock &B: F) {
for …Run Code Online (Sandbox Code Playgroud)