[LLVMdev] Alloca and malloc alignment
Lennart Augustsson
lennart at augustsson.net
Fri Jun 19 16:31:33 PDT 2009
According to the LLVM manual, for both malloc and alloca:
"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.
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).
-- Lennart
More information about the llvm-dev
mailing list