I am porting an LLVM plugin (LLFI) written for LLVM 2.9 to the latest version of LLVM/Clang.
When testing my plugin with an assertions enabled build of LLVM3.2 I get the following error:
opt: /home/kzvr/ubc/llfi/llvm3/llvmsrc/lib/IR/Instructions.cpp:281:
void llvm::CallInst::init(llvm::Value*, llvm::ArrayRef<llvm::Value*>,
const llvm::Twine&): Assertion `(i >= FTy->getNumParams() ||
FTy->getParamType(i) == Args[i]->getType()) && "Calling a function with a bad
signature!"' failed.
0 opt 0x00000000017931a6 llvm::sys::PrintStackTrace(_IO_FILE*) + 38
1 opt 0x0000000001793423
2 opt 0x0000000001792e7b
3 libpthread.so.0 0x00007f0c0279fff0
4 libc.so.6 0x00007f0c018a91b5 gsignal + 53
5 libc.so.6 0x00007f0c018abfc0 abort + 384
6 libc.so.6 0x00007f0c018a2301 __assert_fail + 241
7 opt 0x00000000016e78c4 llvm::CallInst::init(llvm::Value*, llvm::ArrayRef<llvm::Value*>, llvm::Twine const&) + 402
8 LLFI.so 0x00007f0c0165adcb
9 LLFI.so 0x00007f0c0165aa83
10 LLFI.so 0x00007f0c016581c5
11 opt 0x000000000171c02c llvm::FPPassManager::doFinalization(llvm::Module&) + 88
12 opt 0x000000000171c449 llvm::MPPassManager::runOnModule(llvm::Module&) + 1013
13 opt 0x000000000171c8a6 llvm::PassManagerImpl::run(llvm::Module&) + 254
14 opt 0x000000000171cc01 llvm::PassManager::run(llvm::Module&) + 39
15 opt 0x000000000087a089 main + 5591
16 libc.so.6 0x00007f0c01895c8d __libc_start_main + 253
17 opt 0x000000000086bf59
In the plugin code I have many calls to llvm::CallInst::Create, which, based on the above, I believe at least one of which is performed incorrectly. They pretty much all look like this:
ArrayRef<Value*> arrayArgs(args);
Instruction* callInst = CallInst::Create( injectFunc, arrayArgs, fiName, insertInst);
where args is an std::vector, injectFunc is an llvm::Constant*, fiName is an std::string, and insertInst is an llvm::Instruction*
The problem is, as an LLVM newbie, I dont know how to narrow my bughunt down from this point. So I have a few questions:
- How can I find which call to CallInst::Create is the one that causes CallInst::init to fail the assertion?
- Where is the documentation that explains the proper usage of the CallInst class? Google searches yield auto-generated docs of the source code, which I have already pored over to no avail.
- The only difference between the 2.9 and 3.2 version of this plugin (as far as CallInst goes), is the replacement of passing std::vector iterators to CallInst::create, with passing an ArrayRef constructed from the std::vector. Am I constructing the ArrayRef from the Vector improperly?
Thanks in advance for any help, I hope this question isn't too vague.