[LLVMdev] Equivalent alignment of __attribute__((__aligned__))

Chris Lattner clattner at apple.com
Mon Feb 1 12:06:29 PST 2010


On Feb 1, 2010, at 12:01 PM, Garrison Venn wrote:

> Sorry as you interpreted I meant minimum alignment. 
> 
> My issue is in translating from a C struct which has a member aligned with 
> __attribute__((__aligned__)) to a generated packed StructType where I use padding
> to force the alignment of said member. Instances of this struct are placed on the heap
> via malloc. Although I'm currently using static C code to determine the padding size, I'm trying 
> to avoid using such code since I'm not sure which llvm platforms don't support __attribute__((__aligned__)). 
> Knowing that malloc will give me an address aligned to any platform supported datatype, and knowing 
> this minimum alignment (which I believe is equivalent to __attribute__((__aligned__))), I could
> calculate the above value. I'm currently using the alignment of long double instead.
> 
> Any recommended way of determining this value or doing the equivalent?

There is no good way to do this at the LLVM IR level, and you need a lot more information than just attribute(aligned).  Take a look at the code in clang that handles record layout, for example.

-Chris



More information about the llvm-dev mailing list