[llvm-dev] Getting a pointer to a i8 from a global variable that holds a constant string

Snehasish Kumar via llvm-dev llvm-dev at lists.llvm.org
Tue Apr 11 12:45:03 PDT 2017


Hi Lorin

You might want to take a look at the CreateGlobalStringPtr method in the
IRBuilder class. It should allow you to insert the string and construct the
appropriate GEP automatically.

http://llvm.org/docs/doxygen/html/classllvm_1_1IRBuilder.html#ab81bf85457770dc76f2e536f201db219

Regards,
Snehasish

On Sat, Apr 8, 2017 at 5:32 PM, Tim Northover via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

> Hi Lorin,
>
> On 8 April 2017 at 05:18, Lorin Atzberger via llvm-dev
> <llvm-dev at lists.llvm.org> wrote:
> > return llvm::ConstantExpr::getGetElementPtr(nullptr,c,
> > const_ptr_14_indices);
>
> You need to be using the GlobalVariable as the base of the GEP, not
> the ConstantDataArray. Then since it's been initialized to the string
> you want, your GEP will pick up the first element of that string. The
> ConstantDataArray isn't a pointer (it's an [N x i8], notionally in
> registers).
>
> Cheers.
>
> Tim.
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>



-- 
Snehasish Kumar
School of Computing Science
Simon Fraser University
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170411/d5289966/attachment.html>


More information about the llvm-dev mailing list