[LLVMdev] StructType member offset

Duncan Sands baldrick at free.fr
Tue Oct 26 06:25:47 PDT 2010


Hi Alex,

I think you are looking for getStructLayout from TargetData (the
StructLayout type is also defined in TargetData.h).

Ciao,

Duncan.

> how can i correctly calculate the size of a member of a struct
> (including alignment etc)?
> This doesn't work :
>
>           const StructType *STy = cast<StructType>(Ty);
>           for (StructType::element_iterator I = STy->element_begin(),
>                  E = STy->element_end(); I != E; ++I)
>           {
>               usigned size =I->get()->getScalarSizeInBits(); //often
> returns 0, not what I need
>           }
>
> Basically I want to add up the sizes of the different members to
> calculate the offset (which I want to compare to
> DIType::getOffsetInBits()). Or if there is a direct way to get the
> offset of a struct member without adding their sizes that'd be even better.
>
> Thx,
> Alex
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev




More information about the llvm-dev mailing list