[LLVMdev] Unwind example
Greg Pettyjohn
gregp at ccs.neu.edu
Tue Apr 19 16:42:04 PDT 2005
I'm trying to figure out the unwind primitive.
I've written a program which should:
1. Recursively grow the stack until it reaches a threshold
2. Then unwind and print a message
Instead what happens is:
1. Recursively grow the stack until it reaches a threshold
2. Then it dies with:
Abort trap
Can you point me to an example using uwind that "works" ?
Thanks.
Here's the code:
%str_sp = internal constant [9 x sbyte] c"SP = %i\0A\00" ; <[9 x
sbyte]*> [#uses=1]
%str_msg = internal constant [15 x sbyte] c"Bottom'd Out!\0A\00"
implementation ; Functions:
declare int %printf(sbyte*, ...)
internal void %stack_check() {
entry:
%xyzzy = alloca int ; <int*> [#uses=1]
%spcheck.0 = cast int* %xyzzy to int
%spcheck.1 = setlt int %spcheck.0, -1080000000
br bool %spcheck.1, label %the_return, label %endif
endif:
%tmp.0 = getelementptr [9 x sbyte]* %str_sp, int 0, int 0
%tmp.1 = call int (sbyte*, ...)* %printf( sbyte* %tmp.0, int* %xyzzy)
call void %stack_check()
br label %the_return
the_return:
; ret void
unwind
}
int %main() {
entry:
invoke void %stack_check()
to label %normal_ret
unwind label %exn_ret
exn_ret:
%foo.0 = getelementptr [15 x sbyte]* %str_msg, int 0, int 0
%foo.1 = call int (sbyte*, ...)* %printf(sbyte* %foo.0)
br label %normal_ret
normal_ret:
ret int 0
}
More information about the llvm-dev
mailing list