[LLVMdev] Dereference PointerType?
Daniel Waterworth
da.waterworth at googlemail.com
Tue Oct 20 02:39:58 PDT 2009
2009/10/20 Daniel Waterworth <da.waterworth at googlemail.com>
> Hello,
>
> I'm wondering if it's possible to dereference a PointerType. I have an
> AllocaInst and although I can find the number of elements allocated, (using
> Instruction::getOperand(0)), I can't find a way to get the size of each
> element. What I'd like to do is:
>
> AllocaInst *alloca;
>
> PointerType *ptr_type = dynamic_cast<PointerType*>(alloca);
> assert(ptr_type);
> Type *allocated_type = ptr_type->dereference(); // this is the operation
> that doesn't seem to exist.
> size_t size;
> 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
>
> If it doesn't exist, how do you manage without it? Is there another way to
> write the above code?
>
> Thanks,
>
> Daniel
>
Spot the deliberate mistake [=
PointerType *ptr_type = dynamic_cast<PointerType*>(alloca);
should be,
const PointerType *ptr_type = dynamic_cast<const
PointerType*>(alloca->getType());
and,
Type *allocated_type = ptr_type->dereference();
should probably be,
const Type *allocated_type = ptr_type->dereference();
Daniel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20091020/5ea65e1d/attachment.html>
More information about the llvm-dev
mailing list