[LLVMdev] Matching struct layouts.

Devang Patel dpatel at apple.com
Fri May 16 09:20:38 PDT 2008


On May 16, 2008, at 1:40 AM, Mahadevan R wrote:

> On Fri, May 16, 2008 at 12:31 PM, Duncan Sands <baldrick at free.fr>  
> wrote:
>>>> 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?
>>>
>>> There are no bitfields, but it does have a variable length array  
>>> at the end.
>>> There are no unions.
>>
>> You could use llvm-gcc to convert the struct to an LLVM type.
>> Otherwise, it wouldn't be too hard to convert the struct by
>> hand as long as it doesn't have any exotic types in it.  A
>> VLA at the end (with element type T) is currently represented
>> by placing a field of type T at the end (i.e. just one element).
>
> But can I assume that both gcc and LLVM will layout the structure
> in the same way (member alignment, padding)?

On LLVM side, llvm-gcc is responsible to create LLVM IR with  
appropriate struct layout.  llvm-gcc interprets GCC's struct layout  
while creating LLVM IR. GCC's struct layout at this point is target  
specific. So any difference between gcc and LLVM struct layout is a  
bug or oversight in interpreting GCC's struct layout. If there is a  
bug in GCC's struct layout then llvm-gcc will create bug-to-bug  
compatible struct layout :)

-
Devang



More information about the llvm-dev mailing list