[LLVMdev] GetElementPtr

John McCall rjmccall at apple.com
Mon Dec 12 17:25:01 PST 2011

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.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20111212/03fb2ba0/attachment.html>

More information about the llvm-dev mailing list