[LLVMdev] RFC: Exception Handling Proposal II

Duncan Sands baldrick at free.fr
Sun Nov 28 09:50:05 PST 2010


Hi John,

>> I'm pointing out that if the invoke instruction
>> is removed and catch information is attached to entire basic blocks, then if no
>> care is taken then it is perfectly possible to use %x before it is defined as
>> explained in my previous email, blowing up the entire LLVM system.  Clearly the
>> solution is to not allow this by not allowing values defined in a basic block
>> to be used in a handler for that block;
>
> If we take this route — and I think we should, although I'd like to see region
> chaining in first — I see two reasonable solutions.  The first is what you've
> said, that effectively there's an edge from the beginning of the block;  the
> second is a slight twist, that the edge leaves from the end of the phis.  I
> think the latter will greatly simplify every transformation which ever inserts
> a phi, and in particular mem2reg.  Since phis can't throw, it should be
> equivalent anyway.

that makes sense to me, but needs to be thought about carefully.

>> In Ada you can throw and exception inside a destructor and it does not lead
>> to program termination.
>
> Interesting.  I assume that the personality still sees these as just cleanups,
> so this must be implemented by running the destructor in a handler which
> aborts both unwinds and throws the Program_Error?

Right.  The dwarf exception library doesn't mind if you throw a new exception
inside a cleanup, it just unwinds it.  ["Cleanups don't throw" is a C++ specific
concept that is built on top of the basic unwinder facilities; gcc does it by
wrapping cleanup code in a no-throw filter, either explicitly or implicitly via
no-throw regions, which are an optimization but conceptually no different to a
no-throw filter].  So the Ada stuff can just wrap the running of destructors in
a catch-all, and if a destructor throws it then finalizes the original
exception (finalizing exceptions never throws in Ada) and throws a new one
(Program_Error) instead, which then unwinds in the usual way, which may mean
being caught in the containing function if the scope being left is wrapped in
one which catches Program_Error.  Of course this means that in LLVM it would be
wrong to bake in a rule like "cleanup code never throws", but hopefully no-one
was suggesting that.

Ciao,

Duncan.

PS: If you and Bill came to a consensus over the definition of regions etc,
it would be nice to see a revised proposal from Bill that incorporates it.



More information about the llvm-dev mailing list