Argument's types mismatch when creating CallInst.

Hello. I have an .bc, which defines @foo(%type* arg1, %type* arg2, %type* arg3).
Firstly, i do this:

runtimeModule = getLazyIRFileModule(“runtime.bc”, smd, llctx);

then this:

fooFunction = runtimeModule->getFunction(“foo”);
myType = runtimeModule->getTypeByName(“type”);

After that, i’m creating another module:

myModule = new Module(“My Module”, llctx);

and create some AllocaInsts with type %type:

AllocaInst * retZval = new AllocaInst(myType,

Finally, i do

CallInst::Create(fooFunction, args_vector, “”, currentBB);

Everything seems to be fine so far.
Now i link two modules together and run Verifier:

llvm::Linker linker(“myModule”, runtimeModule);
linker.LinkInModule(myModule, &err);

This gives me error:
Call parameter type does not match function signature!
%“arg1” = alloca %type
%“type 0x801e9b550”* %0 = call i32 @foo(%type* %"~3", %type* %“arg2”, %type* %“arg3”)

What’s interesting - if i dump myModule before verifying, manually put @foo and %type definitions into it, then opt -verify do not complain.

Am i doing something wrong or is it a bug?

A CallInst in one module can't reference a Function in another module.
Build a declaration of foo in the module where you're building the
call, and call that.


Hmm, before emitting any code i’ve added this:


Now i see @foo declaration when dumping myModule, but the error is still same.


I saw the same error in case of passing arguments of wrong types to
CallInst. So, the problem is likely not in Function::Create, it should
be OK, but in CallInst. Could you experiment with adding/removing
arguments in function prototype to determine which one is causing an

Hope it helps,
- Dima.