[LLVMdev] Is alloca instruction allowed within the cycle?

Yuri yuri at rawbw.com
Fri Jun 18 18:20:34 PDT 2010


I am running this code in JIT on x86 (32 bit).
It crashes when 'alloca %object' instruction is within the body of the 
cycle, and it finishes successfully when this instruction is in the 
beginning of main (outside the cycle). Crash occurs in the middle of the 
cycle after few hundreds of thousands iterations.

What is wrong? Does alloca inside the cycle forces it to allocate it on 
stack for every iteration instead of only once?
If this is the case why verify doesn't complain?

Yuri


--- code ---

%object = type { i8, i8, i8}
@str2 = private constant [1 x i8] zeroinitializer

define void @main() {
for.init:
   %i = alloca i32
   store i32 0, i32* %i
   br label %for.end

for.body:
   %obj = alloca %object
   %str = getelementptr inbounds [1 x i8]* @str2, i32 0, i32 0
   call void @obj_constr(%object* noalias sret %obj, i8* %str)
   call void @obj_destr(%object* %obj)
   br label %for.incr

for.incr:
   %incr = load i32* %i
   %incr3 = add i32 %incr,
   store i32 %incr3, i32* %i
   br label %for.end

for.end:
   %iload = load i32* %i
   %xcmp = icmp sge i32 %iload, 100000000
   br i1 %xcmp, label %xend, label %for.body

xend:
   ret void
}




More information about the llvm-dev mailing list