[llvm-dev] Get elements from a getelementptr constant expression

Damilola Orikogbo via llvm-dev llvm-dev at lists.llvm.org
Tue May 30 20:20:02 PDT 2017


Hello,

I apologize, I am new to the list-serve (joined on the 25th) and am not
quite sure how it works.

I didn't reply to Hans because the llvm/ clang distribution I have
installed doesn't allow me to use that command line option, I will respond
in a bit.  And I asked anther question simply because no one replied to my
first question.

I have been using llvm for about a week, so I am not sure how to ask my
question succinctly but I am trying, please bear with me.

In reply to your response, I will try that out tomorrow and hopefully be
able to make some headway.

I have been searching previous emails and have found that some people have
cast the getelementptr in the Instruction i posted in this original email
thread to a constantexpr or GEPOperator and have been able to get
information that way, but I can't quite seem to figure it out.

 *Ex email thread:*
https://groups.google.com/forum/#!topic/llvm-dev/_F-PFACaHbU
<https://groups.google.com/forum/#!topic/llvm-dev/_F-PFACaHbU>


If anyone has tried this approach and could provide some more information
going this route, I would appreciate that as well.

Cheers,

Dami

On Tue, May 30, 2017 at 10:37 PM, Tim Northover <t.p.northover at gmail.com>
wrote:

> Hi,
>
> On 30 May 2017 at 19:13, Damilola Orikogbo via llvm-dev
> <llvm-dev at lists.llvm.org> wrote:
> >  store i32 (...)** bitcast (i8** getelementptr inbounds ([5 x i8*], [5 x
> > i8*]* @_ZTV9Rectangle, i32 0, i32 2) to i32 (...)**), i32 (...)*** %5,
> align
> > 8
> >
> > and was wondering how to access the indices of the getelementptr. How
> would
> > i print out all pointers stored from index 0 to 5.
>
> You really need to start replying to your own threads. The one I
> noticed this morning was particularly useless compared to your message
> from 25th May, and you didn't even clarify your problem for Hans after
> he replied.
>
> That said, if you'd identified a vtable you would insert code to GEP
> element N and then pass the result to something like a printf
> expecting a %p. Of course you need to know in advance that your vtable
> contains 5 entries.
>
> So you'd create a bunch of instructions looking vaguely like:
>
>     call void @printf(@WHATEVER_FOR_PERCENT_P, bitcast(i8**
> getelementptr inbounds([5 x i8*], [5 x i8*]* @_ZTV9Rectangle, i32 0,
> i32 N) to i8*)
>
> The chances are you won't always have a @_ZTV* global as a base though
> (that's the entire point of dynamic dispatch). In which case you'd
> have to create a bunch of instructions like:
>
>     %tmp = getelementptr inbounds [5 * i8*], [5 x i8*]* %vtable, i32 0,
> i32 N
>     %tmp1 = bitcast i8** %tmp to i8*
>     call void @printf(@WHATEVER_FOR_PERCENT_P, %tmp1)
>
> Tim.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170530/dafec7d9/attachment.html>


More information about the llvm-dev mailing list