[LLVMdev] newbie question for type comparison

Gordon Henriksen gordonhenriksen at mac.com
Mon Apr 21 12:34:22 PDT 2008


On Apr 21, 2008, at 15:07, John Criswell wrote:

>> 1. For getting ALL struct allocation, when I use
>>
>>        if( (AI = dyn_cast<AllocaInst>(&*i)))
>>          if(AI->getOperand(0)->getType()->getTypeID() ==
>> Type::StructTyID) {
>>
>> to get all alloca instructions allocating a structure, it does not
>> work. In my gdb session, I've got the following dumps:
>>
> I'm not sure why the above doesn't work.  My best guess is that the
> allocated type is not an operand (since it is not an LLVM Value) but  
> is
> an attribute (for lack of a better word) of the alloca instruction.

Correct.

> My suggestion is to use the getAllocatedType() method of the  
> AllocaInst
> class.  I'm pretty sure it does what you want:
>
> if (AI->getAllocatedType()->getTypeID() == Type::StructTyID)
>

Better: if (isa<StructType>) or if (StructType *sT =  
dyn_cast<StructType>).

— Gordon





More information about the llvm-dev mailing list