[LLVMdev] GetElementPtr

Ryan Taylor ryta1203 at gmail.com
Mon Dec 12 17:31:30 PST 2011


Ok, thanks.

I'm just curious since when I'm doing the calculations, I need to make sure
all operands are of the same size. So I suppose I will simply pick the
largest width.

On Mon, Dec 12, 2011 at 5:25 PM, John McCall <rjmccall at apple.com> wrote:

> On Dec 12, 2011, at 5:15 PM, John Criswell wrote:
>
>  On 12/12/11 7:00 PM, Ryan Taylor wrote:
>
> So in this example:
>
> %idx = getelementptr { float*, i32 }* %MyStruct, i64 0, i32 1
> Why is it picking i64 for the index but i32 for the offset?
>
>
> I believe pointers and arrays are indexed using i64 (or some integer size
> matching the pointer size) and structure elements are indexed using i32.
>
>
> This.  Frontends generally emit non-struct indexes as appropriately-sized
> integers to avoid (possibly) unwanted problems with extension.  In this
> case, since that index is constant 0, it's unimportant, but you can imagine
> cases where it would.  Struct indexes, on the other hand, must be constant
> and non-negative, so the choice of index width doesn't matter.
>
> John.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20111212/b9f1ebbc/attachment.html>


More information about the llvm-dev mailing list