get size of a GlobalVariable

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?

Thanks in advance,
Eduardo

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.