Hi Team,
I am migrating one of the Pass that was written for llvm2.2 or older to llvm3.1. The code snippet looks like the following:
Constant *func;
void add( Module *M) {
func = M->getOrInsertFunction(“func”, Type::getVoidTy(M->getContext()), NULL);
}
virtual bool runOnModule(Module &M) {
add (&M);
for(Module::iterator F = M.begin(), E = M.end(); F != E; ++F) {
Function *fun = dyn_cast(F);
Value *Opts[1];
BasicBlock &bb = F->getEntryBlock(), *newBB;
newBB = BasicBlock::Create(M.getContext(), “initfunc”, F, &bb);
CallInst::Create(func, makeArrayRef(Opts, 1) , “”, newBB);
BranchInst::Create(&bb, newBB);
}
}
The pass compiles fine but when I use ‘opt’ to instrument a simple C program then I get the following exception:
$ opt -o a.bc -load /data/llvm3.1/Release+Asserts/lib/Dat.so -MyPass < malloc.bc
opt: Instructions.cpp:269: void llvm::CallInst::init(llvm::Value*, llvm::ArrayRefllvm::Value*, const llvm::Twine&): Assertion `(Args.size() == FTy->getNumParams() || (FTy->isVarArg() && Args.size() > FTy->getNumParams())) && “Calling a function with bad signature!”’ failed.
In older llvm, I had the following line:
CallInst::Create(func, Opts, Opts , “”, newBB);
Which I have now modified for llvm3.1 to:
CallInst::Create(func, makeArrayRef(Opts, 1) , “”, newBB);
Please can anyone tell the reason of this opt error?
Thanks.
–Ahmad