[LLVMdev] creating a variable structure, getting offset pointer
edA-qa mort-ora-y
eda-qa at disemia.com
Sat Feb 2 22:54:50 PST 2013
I'm creating a structure type which has a variable component. I'm not
clear on the correct way to ensure the alignment of the variable part is
correct and how to get the offset.
For example, I have a wrapping structure format that looks like this:
struct wrap:
int32 ref_count
PointerType(FunctionType) func_ptr
T data
Where 'T' is the desired extra data. I need to ensure that T is always
at the same offset in this structure (thus I can't simply create a
structure with all the elements). T will be used opaquely (a pointer
passed to func_ptr as the first parameter, the function then casts it to
the correct pointer type).
I currently achieve this by making my wrap structure like this:
struct wrap:
int32 ref_count
PointerType(FunctionType) func_ptr
PointerType(Int8) generic_ptr
I then allocate a structure large enough for this base and type T. I
then just assume T has the same address as "generic_ptr" and use
CreateStructGEP to get at that address. However, depending on type T I'm
not sure this will always create the correct alignment requirements.
How can I correctly create such a structure which guarantees the correct
alignment of the T data structure?
--
edA-qa mort-ora-y
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Sign: Please digitally sign your emails.
Encrypt: I'm also happy to receive encrypted mail.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 261 bytes
Desc: OpenPGP digital signature
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130203/cbd5eff9/attachment.sig>
More information about the llvm-dev
mailing list