[LLVMdev] get size of a GlobalVariable

John Criswell criswell at illinois.edu
Sun Nov 18 09:33:03 PST 2012


On 11/18/12 11:16 AM, Eduardo wrote:
> Hi,
>
> How can I get the size of a global variable if I have a reference to
> the corresponding llvm::GlobalVariable object? What if this variable
> is an array or struct, how can I get the size of the whole variable?

A GlobalVariable will always have a pointer type.  Find the contained 
type of the pointer type, and then use the DataLayout class to determine 
the size of the contained type.

See 
http://llvm.org/viewvc/llvm-project/safecode/branches/release_32/lib/InsertPoolChecks/RegisterBounds.cpp?revision=168085&view=markup 
for an example.

-- John T.

>
> Thanks in advance,
> Eduardo
> _______________________________________________
> 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