<div dir="ltr">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.<br><br>Had a couple of thoughts:<br>
<br>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?).<br>
<br>Tested the out-of-line = default case, this optimization doesn't seem to fire and I still see the derived dtor on the stack.<br><br>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.<br>
<br>Given:<br>struct base { virtual ~base() { f(); } };<br>struct derived: base { };<br><br>This:<br>derived d;<br>derived *p = new derived();<br>delete p;<br><br>Shows the base dtor run without the derived dtor in the call stack, but this:<br>
<br>base *b = new derived();<br>delete b;<br><br>does show the derived dtor in the call stack. So that seems OK.<br><br><br>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?<br>
<br><br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Nov 11, 2013 at 8:42 PM, Rafael Espíndola <span dir="ltr"><<a href="mailto:rafael.espindola@gmail.com" target="_blank">rafael.espindola@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On 11 November 2013 23:35, David Blaikie <<a href="mailto:dblaikie@gmail.com">dblaikie@gmail.com</a>> wrote:<br>

> This optimization fires if the derived dtor has no work to do (and thus<br>
> without the optimization Clang emits a derived dtor that simply contains a<br>
> call to the base dtor?)?<br>
><br>
> The usual "What does GCC do?" might be helpful - do they ever do this? Do<br>
> they do it only > -O0?<br>
<br>
</div>They never emit an alias from derived to base (even with local<br>
classes). With optimizations you get a direct call, but I am not sure<br>
exactly which optimization is doing it.<br>
<br>
Cheers,<br>
Rafael<br>
</blockquote></div><br></div>