[LLVMdev] allocating an array

Duncan Sands baldrick at free.fr
Wed Jul 16 13:59:40 PDT 2008


Hi,

> Obviously this is wrong, but I don't see how I can use the value from
> 'size' to allocate the necessary space for this array with alloca. I
> could use a pointer to an array in the struct type, instead of a
> direct array, and use two allocas (one for the struct and one for the
> array data). But then there is no real reason to use the array type
> anymore, a pointer to the first element (like llvm-gcc generates for
> C/C++ arrays) would be much simpler. Or am I missing something?

if the length is %n, you can alloca %n i8's:
  %x = alloca i8, i32 %n
[Well, I guess you need to allocate a bit more to include
the overhead of the length field in your struct.]
Then bitcast %x (which is an i8*) to a pointer to
your struct type.

Ciao,

Duncan.



More information about the llvm-dev mailing list