[tree-ssa] Fun with exceptions -- opinions needed

Chris Lattner sabre@nondot.org
Tue Jun 17 14:05:00 GMT 2003


>>> The copies are an explicit
>>>representation of the necessary data and control flow in this situation
>>>(namely the separation of the side-effect of calling the function from the
>>>side-effect of overwriting the variable).

>> It certainly seems that way.  This makes me wonder what LLVM does since
>> apparently it doesn't have copies.

... and Felix said:

> "exceptional control flow edges" is an "invoke-with-catch"
> instruction instead of a "call" instruction.  I don't see any
> evidence on the developer's list that anyone has looked at
> implementing exception support for real yet.  It seems to me
> they're going to run into the same problem you did.

Felix is right, we haven't implemented the runtime support for exceptions
yet.  Perhaps I'm not understanding the problem correctly, but I don't
think that this will be a problem in LLVM.  In LLVM, for this example:

int get();
void bar();
void test(int i) {
 try {
    i = get();
 } catch (...) { };
 if (i != 0)
   bar();
}

The C++ front-end currently spits out:

$ llvmgcc ehtest.cpp -c -o - | llvm-dis
...
void %_Z4testi(int %i.1) {
entry:          ; No predecessors!
        %tmp.0 = invoke int ()* %_Z3getv( )
                        to label %try_exit except label %try_catch              ; <int> [#uses=1]

try_catch:              ; preds = %entry
        %tmp.1 = call sbyte* %__cxa_begin_catch( sbyte* null )          ; <sbyte*> [#uses=0]
        call void %__cxa_end_catch( )
        br label %try_exit

try_exit:               ; preds = %entry, %try_catch
        %i.0.0 = phi int [ %i.1, %try_catch ], [ %tmp.0, %entry ]               ; <int> [#uses=1]
        %tmp.31 = cast int %i.0.0 to bool               ; <bool> [#uses=1]
        br bool %tmp.31, label %then, label %return

then:           ; preds = %try_exit
        call void %_Z3barv( )
        br label %return

return:         ; preds = %try_exit, %then
        ret void
}

LLVM doesn't define what the invoke returns if "get" throws.  Instead,
it's up to the PHI node (oddly named "i.0.0" in this example) to compute
the correct value if an exception gets thrown or not.

I hope this helps, if not, I'm more than happy to run other examples or
explain further.  :)

-Chris

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




More information about the Gcc mailing list