Opt error

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

Hi Ahmad,

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);

this function has no parameters and doesn't return a result.

}

virtual bool runOnModule(Module &M) {

                add (&M);

for(Module::iterator F = M.begin(), E = M.end(); F != E; ++F) {

         Function *fun = dyn_cast<Function>(F);

          Value *Opts[1];

         BasicBlock &bb = F->getEntryBlock(), *newBB;

           newBB = BasicBlock::Create(M.getContext(), "initfunc", F, &bb);

*CallInst::Create(func, makeArrayRef(Opts, 1) , "", newBB);*

But here you pass it an argument. Note you don't need makeArrayRef, you can
just pass Opts. It will be magically turned into an ArrayRef.

Ciao, Duncan.

PS: Opts[1] is not initialized, this will cause problems!

Thanks Duncan. I have noticed that in the older LLVM, the code is passing double pointer as un-initialized:

Value **Opts;
CallInst::Create(func, Opts, Opts , "", newBB);

Is there any alternative of this in llvm3.1 please?

--Ahmad