[llvm-dev] How to create an alloca variable of type i64 in LLVM IR?

Dipanjan Das via llvm-dev llvm-dev at lists.llvm.org
Tue Oct 10 21:07:31 PDT 2017


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?

-- 

Thanks & Regards,
Dipanjan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20171010/22cf39eb/attachment.html>


More information about the llvm-dev mailing list