The TargetData class gives you the size of the pointer. (getPointerSize and getPointerSizeInBits).<br>Can it help you ?<br><br><br><div class="gmail_quote">On Wed, May 6, 2009 at 6:55 AM, Talin <span dir="ltr"><<a href="mailto:viridia@gmail.com">viridia@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="im">Chris Lattner wrote:<br>
> On May 5, 2009, at 8:09 PM, Talin wrote:<br>
><br>
><br>
>> I wanted to mention, by the way, that my need/desire for this hasn't<br>
>> gone away :)<br>
>><br>
>> And my wish list still includes support for something like uintptr_t<br>
>> - a<br>
>> primitive integer type that is defined to always be the same size as a<br>
>> pointer, however large or small that may be on different platforms.<br>
>> (So<br>
>> that the frontend doesn't need to know how big a pointer is and can<br>
>> generate the same IR that works on both 32-bit and 64-bit platforms.)<br>
>><br>
><br>
> Why not just use a pointer, such as i8*?<br>
><br>
</div>Suppose I have an STL-like container that has a 'begin' and 'end'<br>
pointer. Now I want to find the size() of the container. Since you<br>
cannot subtract pointers in LLVM IR, you have to cast them to an integer<br>
type first. But what integer type do you cast them to? I suppose you<br>
could simply always cast them to i64, and hope that the backend will<br>
generate efficient code for the subtraction, but I have no way of<br>
knowing this.<br>
<br>
Now, I'm going to anticipate what I think will be your next argument,<br>
which is that at some point I must know the size of the result since I<br>
am assigning the result of size() to some interger variable eventually.<br>
Which is true, however, if the size of that eventual variable is smaller<br>
than a pointer, then I want to check it for overflow before I do the<br>
assignment. I don't want to just do a blind bitcast and have the top<br>
bits be lopped off.<br>
<br>
The problem of checking for overflow when assigning from an integer of<br>
unknown size to an integer of known size is left as an exercise for the<br>
reader.<br>
<div><div></div><div class="h5">> -Chris<br>
><br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
</div></div></blockquote></div><br>