[LLVMdev] How to code catch-all in the new exception handling scheme?

Bill Wendling wendling at apple.com
Tue Sep 27 04:10:21 PDT 2011


On Sep 25, 2011, at 1:02 AM, Duncan Sands wrote:

> Hi Talin,
> 
>> I'm looking at the docs, and while it refers to a "catch-all" clause,
> 
> hopefully Bill will get rid of the first reference to "catch-all" since
> that section is inaccurate.
> 
I *think* this is now correct. Please check. :)

> it doesn't
>> describe how to construct one.
> 
> There is in general no such thing as a catch-all: it depends on the personality
> function (i.e. the language), and, for example, the Ada language doesn't have
> one (it has something that catches all Ada exceptions, but it won't catch C++
> exceptions).
> 
This is true in a sense that a catch-all is encoded the same way as any other catch type. So for C++, you would specify a catch-all like this:

 %exn = landingpad { i8*, i32 } personality i32 (...)* __gxx_personality_v0
           catch i8* @_ZTIi
           catch i8* null

A 'null' value is C++'s way of saying "this is a catch-all". Ada uses a global variable (function?) for this. To the new EH scheme, they are indistinguishable from a "normal" catch.

> To get a cleanup add the "cleanup" flag to the landingpad instruction.  That
> said, I'm ruminating on whether the cleanup flag should be removed: instead
> there would always be an implicit cleanup.  As an optimization, the code
> generators would not output a cleanup into the exception handling tables if
> no useful code is executed when the cleanup is run.  This seems to be what
> recent versions of GCC do.
> 
I'm not a big fan of implicit behavior. :) And it requires an optimization to "cleanup" (yeah, a pun...sue me) the extraneous code we generate, which won't happen at -O0 (right?). Though the optimization you mentioned here would be a nice thing to have with our current scheme.

-bw




More information about the llvm-dev mailing list