[LLVMdev] Unwind example

Chris Lattner sabre at nondot.org
Tue Apr 19 17:57:52 PDT 2005


On Tue, 19 Apr 2005, Greg Pettyjohn wrote:

> 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" ?

I have no idea if that test should work for your platform or not, but make 
sure you pass -enable-correct-eh-support to LLC when you compile the 
program.

-Chris


> 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
> }
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://mail.cs.uiuc.edu/mailman/listinfo/llvmdev
>

-Chris

-- 
http://nondot.org/sabre/
http://llvm.cs.uiuc.edu/




More information about the llvm-dev mailing list