[LLVMdev] the getelementptr noop problem
ccarter at cs.uiuc.edu
Sun Sep 29 23:58:01 PDT 2002
Chris Lattner wrote:
>>so i confess i'm still not clear on what the first index into
>>getelementptr is all about.
>I'm sure you're not the only one. :) This is one of the wierdest aspects
>of LLVM to the unaccustomed.
>>it makes perfect sense for an example like
>>getelementptr %mystruct * %reg100
>>to just return a %mystruct * equivalent to %reg100.
>>it does *not* make sense to me that
>>getelementptr %mystruct * %reg100, uint 0
>>should act the same. for look, what this speaks of to me is indexing the
>>first element in an array. if we are careful to cast it back to %mystruct
>>*, then it should *work*, although it is useless. but, i would not expect
>Ok, think of this as:
>Foo = &Reg;
>Which is a noop if reg is a pointer...
Or better yet, it is:
Foo = Reg + 0
The first index to getelementptr is for type-safe pointer arithmetic.
Casey at Carter.net
ccarter at uiuc.edu
More information about the llvm-dev