<div dir="ltr"><div><br></div><div>Let `x` be the address of a global variable `g` in a program at run-time. LLVM IR produces a store instruction as shown below:</div><div><br></div><div> store i32 30, i32* @g, align 4</div><div><br></div><div>I am writing an LLVM pass which will instrument the program such that `x` is passed to an instrumentation function `func(int addr)` at run-time. I can insert a call to `func` using `IRBuilder` successfully. What I am not being able to do is to insert instrumentation to collect `x`. </div><div><br></div><div> if (StoreInst *store_inst = dyn_cast<StoreInst>(&I)) {</div><div> </div><div> Value* po = store_inst->getPointerOperand();</div><div> if(isa<GlobalVariable>(po)) {</div><div> errs() << "store [pointer]: " << *po << '\n';</div><div> </div><div> Constant *instrument_func = F.getParent()->getOrInsertFunction("func", Type::getVoidTy(Ctx), Type::getInt32Ty(Ctx), NULL);</div><div> </div><div> IRBuilder<> builder(&I);</div><div> builder.SetInsertPoint(&B, ++builder.GetInsertPoint());</div><div> </div><div> Value* args[] = {po};</div><div> builder.CreateCall(instrument_func, args);</div><div> }</div><div> }</div><div><br></div><div>The result of running `opt` is :</div><div><br></div><div> Call parameter type does not match function signature!</div><div> i32* @a</div><div> i32 call void bitcast (void (i64)* @func to void (i32)*)(i32* @a)</div><div> LLVM ERROR: Broken function found, compilation aborted!</div><div><br></div><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><span><div><div dir="ltr"><p>Thanks & Regards,</p>
<div>Dipanjan</div></div></div></span></div></div>
</div>