[LLVMdev] Request documentation for global var syntax

Andrew Lenharth andrewl at lenharth.org
Thu Feb 1 09:20:33 PST 2007

On 2/1/07, Schimmel, Mark <mark.schimmel at windriver.com> wrote:
> Does anyone have any good ideas to verify that the layout of a struct
> from the front end (field offsets and alignment) exactly match LLVM's
> interpretation of that struct?  I want to support packing of structs and
> pragmas/attributes for alignment and validate that the front end and
> back end match.  [ This is a different front end (ie. Not GNU based). ]
> For example:
>         __packed struct S1 {
>                 char c;
>                 double d;
>         };
> If I wanted c at byte offset 0 and d at byte offset 1, how would I
> communicate that to LLVM?  If the user applied another pragma/attribute
> which aligned d at offset 2, how would I communicate that and validate
> it?  The assumption here is that the user could declare a struct type
> whose layout doesn't match the default layout from LLVM.
> Perhaps I could extend llvm-as to accept additional annotations in type
> declarations?
>         %S1 = type align 1 { sbyte at 0, double at 2 }
> I don't see anything like this in the 1.9 grammar.

I added packed structures after 1.9.  They are in CVS head, and
documented in the language guide.  The cfe doesn't support them yet,
but that isn't a problem for you I guess.  (There is a patch floating
around for llvm-gcc, but it hasn't been applied)

You can say:
<{ sbyte, double }> to get an sbyte at offset 0 and a double at offset
1.  In packed mode, a structure has no padding and an alignment of 1.
If you want padding, you must insert the necessary buffering into the
structure in your frontend.
So for you example, you would say:
<{sbyte, sbyte, double}> where the middle sbyte is inserted by the
front end to get the padding for the double to be at 2.

Codegen of packed structures is mildly tested on x86.


More information about the llvm-dev mailing list