[LLVMdev] Dereference PointerType?

Daniel Waterworth da.waterworth at googlemail.com
Tue Oct 20 05:11:49 PDT 2009


I agree, however, I didn't realise there was another method for obtaining
the size until Duncan, correctly, pointed one out. I have since changed my
code to use the getAllocSize method.

Thanks,

Daniel

2009/10/20 Óscar Fuentes <ofv at wanadoo.es>

> Daniel Waterworth <da.waterworth at googlemail.com> writes:
>
> > It may not be the best way to do what I'm trying to do, but it's not
> useless
> > and bogus. Consider the following:
> >
> > %1 = alloca i32* ; %1 is of type i32**, dereferenced it becomes a type
> i32*
> > and
> >                          ; the size of that is sizeof(void *) bytes
>
> What Duncan says is that any valid method for obtaining the size of a
> Type should work for a PointerType, which is just another kind of Type.
>
> >>>>> if (isa<PointerType>(allocated_type)) {
> >>>>>  size = sizeof(void*) * 8;
> >>>>> } else {
> >>>>>  size = allocated_type->getPrimitiveSizeInBits();
> >>>>> }
> >>>>> // size now equals the size (in bits) of the type allocated
>
> --
> Óscar
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20091020/94fe705c/attachment.html>


More information about the llvm-dev mailing list