[LLVMdev] RFC: Exception Handling Proposal Revised

Duncan Sands baldrick at free.fr
Wed Dec 1 09:52:43 PST 2010


Hi Bill,

> General Model
> =============
>
> The unwind edge from an invoke instruction jumps to a landing pad. That landing pad contains code which performs optional cleanups, and then determines which catch handler to call (if any). If no catch handlers are applicable, the exception resumes propagation either to the next enclosing region or out of the function.

I was immediately struck by the fact that you describe cleanups as being run
before dispatching to handlers.  In Ada handlers are run first and any cleanups
are run afterwards.  As far as I know it is exactly the same in C++.  Take your
example.  I rewrite it with more explicit scopes:

void bar() {
   try {
     foo();
     { // new scope
       A a;
       foo();
       { // new scope
... etc...
       } // end scope
     } // end scope
   } catch (int i) {
   ... etc ...
}

Here cleanups for "a", "b" etc are only run before the handlers are executed
because they are in inner scopes, and so are cleaned by unwinding before the
"try" scope is reached.  Consider the following example instead:

void bar() {
   try {
     A a;
     foo();
   } catch (int i) {
   ... etc ...
}

If you check the assembler you will see that the destructor for "a" is run
before branching to the handler.

I will comment on the rest later, once I have absorbed it.

Ciao,

Duncan.



More information about the llvm-dev mailing list