[llvm-dev] llvm instrumentation failed

Muhui Jiang via llvm-dev llvm-dev at lists.llvm.org
Thu Sep 6 08:22:17 PDT 2018


Hi

I reviewed some questions about instrumentation and try to learn from them
to do a simple instrumentation by writing a new pass.

For example, for every basicblock, I would like to assign a block id and
call the printf or my own print function to handle the block id. Suppose
the block id is a string.

My code is below:

   int inst_blocks = 0;

   LLVMContext& Ctx = M.getContext();

   Constant* c = M.getOrInsertFunction("printf",Type::getVoidTy(Ctx),
Type::getInt32Ty(Ctx), NULL);

   Function* myprint = cast<Function>(c);

   for (auto &F : M)

     for (auto &BB : F) {

         inst_blocks++;

         BasicBlock::iterator IP = BB.getFirstInsertionPt();

         IRBuilder<> IRB(&(*IP));

         Value * ID =
IRB.CreateGlobalStringPtr(StringRef(std::to_string(inst_blocks)));

         Value* args[] = {ID};

         IRB.CreateCall(myprint, args);

     }


I compiled the pass successfully and then try to use -Xclang -load -Xclang
pass.so to compile my target C code. However, I come across the below
exception

clang-4.0: /home/jmh/Downloads/llvm-4/llvm/lib/IR/Instructions.cpp:263:
void llvm::CallInst::init(llvm::FunctionType*, llvm::Value*,
llvm::ArrayRef<llvm::Value*>,
llvm::ArrayRef<llvm::OperandBundleDefT<llvm::Value*> >, const
llvm::Twine&): Assertion `(i >= FTy->getNumParams() || FTy->getParamType(i)
== Args[i]->getType()) && "Calling a function with a bad signature!"'
failed.

I even do not know how to debug. Do I miss anything important? Thank you so
much for your help

Regards
Muhui
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180906/01adb4d8/attachment.html>


More information about the llvm-dev mailing list