[LLVMdev] Catching C++ exceptions, cleaning up, rethrowing
Paul J. Lucas
paul at lucasmail.org
Fri Mar 23 06:27:30 PDT 2012
On Mar 22, 2012, at 5:29 PM, Bill Wendling wrote:
> On Mar 22, 2012, at 11:40 AM, Paul J. Lucas <paul at lucasmail.org> wrote:
>
>> Unfortunately, I'm not following. How is having the code that catches all exceptions in a separate function different from what I proposed (putting the try/catch in the thunks)? (Ideally, I want to minimize layers of function calls.) Again for reference:
>
> No reason. But if you have the 'try{}catch(...){}', then it should run the d'tors for you. There's no reason for you to have a "run_dtors" function there.
How does the C++ implementation "know" to run the d'tors for me since the C++ objects that were created on the stack were created by JIT'd code, first via alloca to allocate StructTypes of the right size (char[sizeof(T)]) then calling a thunk of the form:
extern "C" void thunk_item_M_new( void *addr ) {
new( addr ) item;
}
where "addr" is the address returned by alloca? To me, it would seem that if you're right, that I shouldn't need any try/catch at all.
When I put tracer print statements in my class's destructors, I can see that they are called only if I explicitly call them via JIT'd code that calls the relevant thunk, e.g.:
extern "C" void thunk_item_M_delete( void *v_that ) {
item *const that = static_cast<item*>( v_that );
that->~item();
}
Given that I have to call the thunks to run the d'tors manually in the normal control-flow case, it would seem that I would also have to call them in the exception-thrown control-flow case -- right?
- Paul
More information about the llvm-dev
mailing list