[LLVMdev] Structure Types and ABI sizes

Jochen Wilhelmy j.wilhelmy at arcor.de
Fri Feb 18 02:52:20 PST 2011


Hi!

I followed the discussion on structure types with the example

struct I {
   int a;
   char b;
};

struct J : I {
   char c;
};

Dave said that this translates to

%I = type { i32, i8, i16 }
%J = type { %I, i8, i16 }

because the frontend has to communicate the ABI to llvm since llvm is 
language agnostic.
What I really wonder is why it isn't

%I = type { i32, i8 }
%J = type { %I, i16, i8 }

because llvm at least knows alignment rules by

target  datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16...

Therefore llvm has no other choice than assigning %I a size of 8
since an array may consist of %I elements and size of 5 would violate
the aligment of the i32 member.
If the ABI requires that member c has an offset of 8 instead of 5 then
of course a padding behind %I is necessary in %J.



-Jochen




More information about the llvm-dev mailing list