<br><br><div class="gmail_quote">2009/10/20 Daniel Waterworth <span dir="ltr"><<a href="mailto:da.waterworth@googlemail.com">da.waterworth@googlemail.com</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hello,<br><br>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:<br>

<br>AllocaInst *alloca;<br><br>PointerType *ptr_type = dynamic_cast<PointerType*>(alloca);<br>assert(ptr_type);<br>Type *allocated_type = ptr_type->dereference(); // this is the operation that doesn't seem to exist.<br>

size_t size;<br>if (isa<PointerType>(allocated_type)) {<br>  size = sizeof(void*) * 8;<br>} else {<br>  size = allocated_type->getPrimitiveSizeInBits();<br>}<br>// size now equals the size (in bits) of the type allocated<br>

<br>If it doesn't exist, how do you manage without it? Is there another way to write the above code?<br><br>Thanks,<br><font color="#888888"><br>Daniel<br>
</font></blockquote></div><br>Spot the deliberate mistake [=<br><br>PointerType *ptr_type = dynamic_cast<PointerType*>(alloca);<br><br>should be,<br><br>const PointerType *ptr_type = dynamic_cast<const PointerType*>(alloca->getType());<br>
<br>and,<br><br>Type *allocated_type = ptr_type->dereference();<br><br>should probably be,<br><br>const Type *allocated_type = ptr_type->dereference();<br><br>Daniel<br>