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

Garrison Venn gvenn.cfe.dev at gmail.com
Mon Feb 1 12:01:11 PST 2010

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?


On Feb 1, 2010, at 14:09, Chris Lattner wrote:

> On Feb 1, 2010, at 11:06 AM, Garrison Venn wrote:
>> Is there a way using llvm::TargetData to determine the alignment of what would be equivalent 
>> to __attribute__((__aligned__))? I'm looking for something like a max alignment number for the
>> target platform so that I know what the max alignment of an address returned by malloc(...) will
>> be.
> Not currently.  The alignment implied by attribute(aligned) is probably not something that TargetData should have, but I think it *does* make sense to have the minimal guaranteed alignment of malloc.
> -Chris

More information about the llvm-dev mailing list