[LLVMdev] Size of structs & arrays

Fraser Cormack frasercrmck at gmail.com
Wed Feb 22 13:56:53 PST 2012


I'm trying to work out the size of a struct so that I can pass this to the
'llvm.memcpy' intrinsic. It's easy to find out how I'm supposed to do this,
as I keep seeing the following:

%Size = getelementptr %T* null, int 1
%SizeI = cast %T* %Size to uint

But I'm unsure how I actually do this in the C++ API. Is the 'null' here a
llvm::ConstantPointerNull? Any help here would be much appreciated.

Additionally, I was wondering whether I can use this method to find out the
size of variable-length arrays, such as [0 x i32], for example? I've tried
doing this and am obviously doing something wrong.

%Size = getelementptr [0 x i32]* %1, i32* null, i32 1
%SizeI = ptrtoint i32* %Size to i64

This gives entirely the wrong result, and I'm not surprised, as it doesn't
look correct. Should I instead be implementing these arrays with a size
associated with them? Something like { i32, [0 x i32]}, for instance?

Cheers,
Fraser


-- 
View this message in context: http://old.nabble.com/Size-of-structs---arrays-tp33341964p33341964.html
Sent from the LLVM - Dev mailing list archive at Nabble.com.




More information about the llvm-dev mailing list