[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
Wed Oct 11 07:31:41 PDT 2017


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

On 11 October 2017 at 06:09, Don Hinton <hintonda at gmail.com> wrote:

> If you want the value, you'll need to load it first, e.g., by using
> CreateLoad...
>
> hth...
> don
>
> On Tue, Oct 10, 2017 at 9:07 PM, Dipanjan Das via llvm-dev <
> llvm-dev at lists.llvm.org> wrote:
>
>>
>> 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
>>
>> _______________________________________________
>> LLVM Developers mailing list
>> llvm-dev at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>>
>>
>


-- 

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


More information about the llvm-dev mailing list