[LLVMdev] Darwin vs exceptions

Dale Johannesen dalej at apple.com
Wed Dec 12 15:05:58 PST 2007


On Dec 12, 2007, at 11:01 AM, Duncan Sands wrote:

> Hi Dale,
>
>> No, I don't want to change the semantics of invoke, at least I don't
>> think so.
>> When inlining, I want the inlined throw to reach cleanup code as it
>> does.
>> But I want the Unwind_Resume call that ends the cleanup code to be
>> replaced with a control transfer to the handler (or cleanup) in the
>> calling
>> function, i.e. the inliner needs to know the semantics of  
>> Unwind_Resume.
>
> it seems to me that this is extremely tricky to do in general,  
> though it
> is simpler if you suppose the IR was produced by gcc.  Consider this  
> example:

Yes, working my way through the tests I've hit several optimizer  
issues.  Your example is
even worse though:)  In general the eh.exception stuff needs special  
handling beyond
what I said.

> To my mind a perfect solution would be:
> (i) Find a trick (like my catch-all trick) so that invokes always  
> branch to the unwind
> label when an exception unwinds through it.  In other words,  
> preserve the traditional
> semantics of invoke.  This makes life much simpler at the level of  
> the IR optimizers.
> (ii) Add a pass that knows about Unwind_Resume and does the kind of  
> transform described
> above when it isn't too hard.  If it is too hard then it can give up  
> because of (i).
> (iii) At codegen time, completely abandon invoke semantics (invoke  
> doesn't exist there
> anyway) and exploit the way the unwinder works as much as possible.
>
> I've applied the darwin CFA unwinder change and will see if I can  
> find a way of getting (i).


Thanks.  I did find a sledgehammer that works:  replace the catch-all  
with a cleanup,
and don't inline anything that calls Unwind_Resume.  I'm trying to  
come up with something
less stupid.

> Index: gcc-4.2.llvm/gcc/except.c
> ===================================================================
> --- gcc-4.2.llvm.orig/gcc/except.c	2007-12-12 20:55:30.000000000 +0100
> +++ gcc-4.2.llvm/gcc/except.c	2007-12-12 20:56:19.000000000 +0100
> @@ -4053,9 +4053,9 @@
> {
>   /* The default c++ routines aren't actually c++ specific, so use  
> those.  */
>   /* LLVM local begin */
> -  llvm_unwind_resume_libfunc = llvm_init_one_libfunc  
> ( USING_SJLJ_EXCEPTIONS ?
> -                                                        
> "_Unwind_SjLj_Resume"
> -                                                       :  
> "_Unwind_Resume");
> +  llvm_unwind_resume_libfunc =
> +    llvm_init_one_libfunc(USING_SJLJ_EXCEPTIONS ?
> +                          "_Unwind_SjLj_Resume" :  
> "_Unwind_Resume_or_Rethrow");
>   /* LLVM local end */
> }

Seems unlikely, but I'll try it.




More information about the llvm-dev mailing list