[LLVMdev] Structure Types and ABI sizes

Renato Golin rengolin at systemcall.org
Thu Feb 24 01:11:40 PST 2011


On 23 February 2011 19:12, David A. Greene <greened at obbligato.org> wrote:
> If %I is not a "POD for the purposes of layout" type, that it's tail
> padding MUST be overlapped when inherited from.  In this case, we
> end up creating two types for %I, %I and %I' and use %I' as the
> type when it is inherited from.

Some other fun examples...

 ** POD-layout:

struct I { int, char }; // size 8 = { i32, i8 };
struct J : I { char };  // size 12 = { %I, i8 };
struct K : J { char }; // size 12 = { [9 x i8], i8, [2 x i8] };

I is POD-layout, but J is NOT.

 ** Default C-tor:

struct I { int, char }; in C++ has the default and copy constructors
created automatically, right? So I is POD-layout.

But struct A { int, char, A(){} }; has the default constructor
overwritten exactly the same way, but A is not a POD-layout any more.
So:

struct A { int, char }; // size 8 = { i32, i8 };
struct B : A { char };  // size 8 = { [5 x i8], char, [2 x i8] }
struct C : B { char }; // size 8 = { [6 x i8], i8, i8 }

Of course, as David said, all those types have their "normal sized"
components, so there is B-full (8 bytes) and B-inheritable (6
bytes)...

cheers,
--renato




More information about the llvm-dev mailing list