[LLVMdev] Matching struct layouts.

Duncan Sands baldrick at free.fr
Thu May 15 05:02:50 PDT 2008


> I've a situation where I need to build and execute a function on the
> fly (with LLVM of course :-). The function will need to take a pointer
> to a C struct, which is defined by the host. That is, the built
> function will be something like:
> 
> void func(struct XYZ *p)
> {
>     /* need to access members of p here */
> }
> 
> How will I educate LLVM IR about 'struct XYZ' so that the code inside
> can access it's members properly? How can I be sure that the alignment
> and padding of the members of the existing struct layout and the LLVM
> struct layout matches?

If this is an arbitrary struct, it can be quite tricky.  Do you have
to worry about bitfields and variable sized fields (for example a
variable length array at the end)?  What about unions?

Ciao,

D.



More information about the llvm-dev mailing list