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?