r194288 - If a linkonce_odr dtor/ctor is identical to another one, just rauw.

David Blaikie dblaikie at gmail.com
Tue Nov 12 10:21:52 PST 2013


Talked with Chandler a bit (just for a pseudo-random (weighted by
convenience) C++ programmer perspective) about how problematic/surprising
this would be during debugging.

Had a couple of thoughts:

1) In the case of a local "derived" object, we could possibly use inlining
debug info to describe the base dtor call to be an inlined instance of the
derived dtor. On further consideration I'm not sure this works generally
because the choice of aliasing/inlining could be made from another TU (does
this optimization fire for an out of line "= default" definition of a
special member?).

Tested the out-of-line = default case, this optimization doesn't seem to
fire and I still see the derived dtor on the stack.

2) In the case of virtual destruction, I assume this optimization doesn't
fire due to the derived dtor needing to do vtable changes? Maybe? On
experimentation this seems to be the case, though narrowly so.

Given:
struct base { virtual ~base() { f(); } };
struct derived: base { };

This:
derived d;
derived *p = new derived();
delete p;

Shows the base dtor run without the derived dtor in the call stack, but
this:

base *b = new derived();
delete b;

does show the derived dtor in the call stack. So that seems OK.


So... what's the benefit of this optimization compared to letting the
backend inline the known-trivial dtors? Then we'd get the inlining debug
info for free in (1) (and the non-polymorphic cases of (2)) rather than
having to implement a special-case inlining in Clang. Does this fire in
other cases where LLVM cannot do this? Is there measurable overhead in
emitting trivial derived dtors that simply call their base dtor?




On Mon, Nov 11, 2013 at 8:42 PM, Rafael EspĂ­ndola <
rafael.espindola at gmail.com> wrote:

> On 11 November 2013 23:35, David Blaikie <dblaikie at gmail.com> wrote:
> > This optimization fires if the derived dtor has no work to do (and thus
> > without the optimization Clang emits a derived dtor that simply contains
> a
> > call to the base dtor?)?
> >
> > The usual "What does GCC do?" might be helpful - do they ever do this? Do
> > they do it only > -O0?
>
> They never emit an alias from derived to base (even with local
> classes). With optimizations you get a direct call, but I am not sure
> exactly which optimization is doing it.
>
> Cheers,
> Rafael
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131112/92078e7f/attachment.html>


More information about the cfe-commits mailing list