[llvm-commits] [llvm] r96526 - in /llvm/trunk/docs: AdvancedGetElementPtr.html index.html

Duncan Sands baldrick at free.fr
Thu Feb 18 12:44:56 PST 2010


Hi Dan,

>>> +  <a name="lead0"><b>Can I cast an object's address to integer and add it
>>> +                     to null?</b></a>
>>> +</div>
>>> +<div class="doc_text">
>>> +  <p>You can compute an address that way, but you can't use that pointer to
>>> +     actually access the object if you do, unless the object is managed
>>> +     outside of LLVM.</p>
>>> +
>>> +  <p>The underlying integer computation is sufficiently defined; null has a
>>> +     defined value -- zero -- and you can add whatever value you want to it.</p>
>>> +
>>> +  <p>However, it's invalid to access (load from or store to) an LLVM-aware
>>> +     object with such a pointer. This includes GlobalVariables, Allocas, and
>>> +     objects pointed to by noalias pointers.</p>
>> Woah, that's an exciting rule!  Has this always been the case?
> 
> Yep; LLVM has effectively had this rule for a long time. There have been a few
> bug reports on it; the resolution was that the user code was buggy.

it's true that this makes the result of getUnderlyingObject meaningful
(otherwise you could get the address of an object by doing "GEP null,
address_of_object_as_integer", and for this a call to getUnderlyingObject
would return "null" rather than "object").  Thanks for cleaning up the doc -
and thanks for writing it in the first place!

Ciao,

Duncan.



More information about the llvm-commits mailing list