<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Aug 26, 2014 at 1:45 PM, David Blaikie <span dir="ltr"><<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class=""><br><br>On Mon, Aug 18, 2014 at 2:33 PM, Adrian Prantl <<a href="mailto:aprantl@apple.com" target="_blank">aprantl@apple.com</a>> wrote:<br>
> IMO, the best we can do is to use the end of the CompoundStmt as the cleanup location if there is one, and otherwise give up and use line 0.<br>
<br></div>OK. The "let's do better when there's braces" isn't something I'm worrying about for now - it's a possible incremental improvement after we figure out the "worst case" behavior.<div class="">
<br>
<br>><br>> ```<br>> if (c)<br>>   foo(); // cleanups = line 0<br>><br>> if (c) {<br>> }         // cleanups<br>><br>> if (c)<br>>   foo();<br>> else {<br>>   bar();<br>> }       // cleanups<br>

<br></div>In this case, I'm not sure the close } to the else is any better than the last line of the else, it still feels like part of the else, not the end of the if scope.<br><br>Anyway, using line zero (did this by hand and used no-integrated-as because Clang doesn't cope well with emitting line table entries for line 0) here's GDB's behavior in some examples:<br>

<br>GCC is GCC 4.8<br>ToT is Clang ToT<br>End is this patch applied to Clang ToT to use the end of the if as the location<br>Zer is the end patch applied, and then manually editing the assembly (and assembling with the system assembler, not the integrated assembler) to have the non-exceptional dtor call be on line 0.<br>

<br>So we get the totally right behavior from GDB the same as we would by assigning it to the end. In the cases where we get different behavior, it's better - we don't step to lines that don't execute, but we still get a bad location walking up from the dtor call (end up wherever the preceeding code was - which means sometimes we end up on the last line of the function where the EH cleanup is ascribed to). Seems better, but not perfect. (but we have no way to get perfect)<br>

<br></div></blockquote><div><br></div><div>Sorry, just realized I didn't explain the pseudocode. The real code looks like this:<br><br><div>   int b = 0;</div><div>   struct foo {</div><div>     operator bool() { return ++b % 2; }</div>
<div>     ~foo() {}</div><div>   };</div><div>   void func() {}</div>   int x[] = {1, 2, 3};<br><div>   for (int a : x)</div><div>     if (foo f = foo())</div></div><div> <br>So the loop runs 3 times, the condition goes true, false, true, and there's a dtor at the end of the 'if' (but not the end of the loop or anything else).<br>
<br>My attempts to actually change Clang to produce line zero, even while disabling the integrated assembler, are incomplete - so far they've also caused other instructions to end up at line zero, so I haven't nailed it down entirely... - hence the asm hacking to get clear results for now.<br>
<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><font face="courier new, monospace">1:   for<br>
2:     if<br>3:       func();<br>4: }<br><br>GCC: 1 2 3 1 2 1 2 3 1 4<br>ToT: 1 2 3 2 1 2 2 1 2 3 2 1 4<br>End: 1 2 3 3 1 2 3 1 2 3 3 1 4<br>Zer: 1 2 3 1 2 1 2 3 1 4, dtor skipped and ascribed to 4<br>
<br>1:   for<br>2:     if<br>3:       func();<br>4:     else<br>5:       func();<br>6: }<br><br>GCC: 1 2 3 1 2 5 1 2 3 1 6<br>ToT: 1 2 3 2 1 2 5 2 2 3 2 1 6<br>End: 1 2 3 1 2 5 1 2 3 1 6<br>Zer: 1 2 3 1 2 5 1 2 3 1 6, dtor skipped and ascribed to 5<br>

<br>1:   for<br>2:     if<br>3:       ;<br>4:     else<br>5:       ;<br>6: }<br><br>GCC: 1 2 5 1 2 5 1 2 5 1 6<br>ToT: 1 2 2 1 2 2 1 2 2 1 6<br>End: 1 2 5 1 2 5 1 2 5 1 6<br>Zer: 1 2 1 2 1 2 1 6, dtor skipped and ascribed to 6<br>

<br>1:   for<br>2:     if<br>3:       ;<br>4: }<br><br>GCC: 1 2 3 1 2 3 1 2 3 1 4<br>ToT: 1 2 2 1 2 2 1 2 2 1 4<br>End: 1 2 3 1 2 3 1 2 3 1 4<br>Zer: 1 2 1 2 1 2 1 4, dtor skipped and ascribed to 4</font><br><br>> ```<br>

><br>> <a href="http://reviews.llvm.org/D4956" target="_blank">http://reviews.llvm.org/D4956</a><br>><br>><br></div>
</blockquote></div><br></div></div>