How to create an alloca variable of type i64 in LLVM IR?

To create a stack based (local) 64 bit integer in LLVM IR, I used:Value *var = builder.CreateAlloca(Type::getInt64Ty(Ctx));

I wish to pass this variable to a function “void foo(unsigned long)”. I created the signature of function foo() as follows:

Constant *func = M->getOrInsertFunction(“foo”, Type::getVoidTy(Ctx),Type::getInt64Ty(Ctx), NULL);

To pass the newly created variable var to foo():

Value *args[] = {var};
builder.CreateCall(func, args);

However, LLVM backend throws assertion error: “Calling a function with a bad signature!”

If I print the types of the following:
errs() << *Type::getInt64Ty(Ctx) << ", " << *var->getType();

I can see first one is i64 and second one is i64*; hence the incompatibility. How can I create an alloca variable of type i64?

If you want the value, you’ll need to load it first, e.g., by using CreateLoad…

hth…
don

I figured out the same by compiling a test program to bitcode and then disassembling it. Thanks Don.