[LLVMdev] GetElementPtrInst Again!

Reid Spencer reid at x10sys.com
Fri Nov 21 16:35:02 PST 2003


On Fri, 2003-11-21 at 14:35, Chris Lattner wrote:
> On Fri, 21 Nov 2003, Reid Spencer wrote:
> > When I set up the call, I get the following from that pesky :) verifier:
> 
> Ah, but it's so helpful!  :)

It is actually. It is ensuring that my compiler is correct which is one
of the hardest things to do!

> > So, in LLVM are arrays and pointers not equivalent as in "C"?
> 
> Absolutely not.

Aha!

> 
> > What do I have to do to turn my little str_format array into a pointer?
> 
> Try making a: getelementptr [3 x sbyte]* %_str_format_, long 0, long 0
> 
> This means:
>    [3 x sbyte]* %_str_format_,      ; Start from _str_format_
>    long 0,                          ; Get the first [3 x sbyte] array pointed to
>    long 0                           ; Get the first element in the array
> 
Okay, so getelementptr gives you a pointer to the last thing indexed,
right? So, if I just use a single long 0 operand on a global array, I
get a pointer to an array in its entirety. That is the pointer type is
[count x type].  If I use two long 0 operands, I get a pointer to the
first element of the array so that the type of the pointer is just
"type".  I had assumed that, since the address of the 0th element of an
array and the address of the array are the same that this equivalence
would be recognized. But, apparently not.  I can see why, however, a
pointer to the whole array and a pointer to its first element differ in
their type, even though the pointer values are the same. Am I getting
this now?
 
> Also, you can try plunking the equivalent code into the C frontend (either
> manually or through the demo page) to see what it makes, if you get
> confused.  :)
> 
Excellent idea .. I won't have to bug you as much :)

Reid.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20031121/6d662ece/attachment.sig>


More information about the llvm-dev mailing list