[LLVMdev] Alloca Instruction

kapil anand kapilanand2 at gmail.com
Sat Jul 4 12:12:15 PDT 2009


Hi all,

I was reading the description of run-time stack and alloca instructions in
LLVM IR and have a question about the same. Do LLVM alloca instructions
allow the processing on stack across some alloca blocks?

For example, is following code valid?

define i32 @f()
{
       %0 = alloca i8, i32 16
      %1 = ptrtoint i8* %0 to i32
       %2 = add i32 %1, 4
       %3 = inttoptr i32 %2 to i32*
      store i32 5,    i32* %3

      %4 = alloca i8, i32 20
      %kkk = ptrtoint i8* %4 to i32
       %5 = add i32 %kkk, 24                    -----> Access to previous
block
      %6 = inttoptr i32 %5 to i32*
       %7 = load i32* %6
      ret i32 %7

  }

Is this kind of accessing across blocks valid? Are we guaranteed that in
final executable, this offest processing across blocks would be taken care
of properly. I have tried writing some LLVM IRs with these kind of accesses
and am getting correct answer( For example, above code is working fine). But
wanted to make sure that this is a valid operation in IR.

Thanks

--Kapil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20090704/7b252b22/attachment.html>


More information about the llvm-dev mailing list