This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: turning throw into a jump
On Fri, Jul 27, 2001 at 12:00:21PM +0200, Sylvain Pion wrote:
> > > try
> > > {
> > > throw int();
> > > }
> > > catch (int i)
> > > {
> > > }
> > > }
> >
> > Oh, that. No, we can't do that -- there's more going on behind
> > the scenes that it looks.
>
> Could you explain a bit more ?
Well, even with the very very smartest compiler you could only
do something with this case if the catch does not rethrow. And
it could only be sure of that if there are no function calls
within the catch.
But this is something that would have to be optimized at the tree
level before it gets to the current optimizers. What we see now
looks more like:
tmp = __cxa_allocate_exception (sizeof(int))
new (tmp) int ();
__cxa_throw (tmp, typeof(int), NULL);
[...]
if (magic_action == 1) {
obj_ptr = __cxa_begin_catch (magic_eh_ptr);
__cxa_end_catch (magic_eh_ptr);
goto resume;
}
All of these functions do non-trivial things, and it is well
beyond the capabilities of the current optimizers to declare
them all collectively (but not individually) dead.
Much the same way as the compiler will never remove
free (malloc (1));
> void f()
> {
> try {}
> catch (int i) {}
> }
>
> It produced :
>
> _Z1fv:
> .LFB1:
> subl $12, %esp
> .LCFI0:
> addl $12, %esp
> ret
It might be something simple, it might be a long-standing misfeature of
when we commit to allocating space on the local stack frame. I'm not
going to look at it right now -- file a low priority optimization bug.
r~