[LLVMdev] Alloca Instruction
Chris Lattner
clattner at apple.com
Sun Jul 5 10:41:48 PDT 2009
On Jul 4, 2009, at 12:12 PM, kapil anand wrote:
> 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?
No, that code is not valid. Each alloca is considered a distinct
object. First example, if the first one was dead (no direct uses),
the optimizer will delete it. Accessing %0 from %4's pointer will not
work well in general, and is undefined behavior.
-Chris
>
>
> 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
>
>
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
More information about the llvm-dev
mailing list