[LLVMdev] Explicitly Freeing Allocas

Duncan Sands baldrick at free.fr
Fri Jun 19 01:31:47 PDT 2009


Nyx wrote:
> I went ahead and implemented the allocation based on the maximum size of all
> structs seen so far... The problem is, the TargetData object from
> ExecutionEngine gives me a size of 12 for a struct containing a pointer and
> an i64 (on a 32-bit machine). However, the generated code seems to assume an
> alignment of 8, and tries to read the i64 value at offset 8, which obviously
> reads an invalid value.
> 
> Does the getSizeInBytes() method from StructLayout not take the alignment
> into account?

You should use getTypeAllocSize.  You can also get this without knowing
the target using ConstantExpr::getSizeOf.

Ciao,

Duncan.



More information about the llvm-dev mailing list