[LLVMdev] Alloca and malloc alignment

Duncan Sands baldrick at free.fr
Sat Jun 20 05:37:10 PDT 2009


Hi Lennart,

>   "If a constant alignment is specified, the value result of the
> allocation is guaranteed to be aligned to at least that boundary. If
> not specified, or if zero, the target can choose to align the
> allocation on any convenient boundary."
> 
> I don't see the rationale for the second sentence, because it means
> that alloca and malloc without an alignment are basically useless.
> Why?  Because without a specified alignment the allocated memory might
> not be properly aligned for the type that was specified.
> It would be nice if the type argument to alloca&malloc were used to
> determine a minimal acceptable alignment.

it is already used for that: if you supply an alignment of zero then it
uses the ABI alignment for the type.

> I discovered this by using alloca for a 2-element vector of i64, and
> sure enough, the memory wasn't properly aligned and thus useless for
> storing the vector (this was on i386).

Then that's a bug, please open a bug report with details.

Ciao,

Duncan.




More information about the llvm-dev mailing list