<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Aug 7, 2014 at 7:14 PM, Ted Kremenek <span dir="ltr"><<a href="mailto:kremenek@apple.com" target="_blank">kremenek@apple.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div class=""><br><div><blockquote type="cite"><div>On Aug 7, 2014, at 10:10 AM, Manuel Klimek <<a href="mailto:klimek@google.com" target="_blank">klimek@google.com</a>> wrote:</div>
<br><div><span style="font-family:Helvetica;font-size:14px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">On Thu, Aug 7, 2014 at 7:06 PM, Ted Kremenek<span> </span></span><span dir="ltr" style="font-family:Helvetica;font-size:14px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><<a href="mailto:kremenek@apple.com" target="_blank">kremenek@apple.com</a>></span><span style="font-family:Helvetica;font-size:14px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important"> </span><span style="font-family:Helvetica;font-size:14px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">wrote:</span><br style="font-family:Helvetica;font-size:14px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">
<blockquote class="gmail_quote" style="font-family:Helvetica;font-size:14px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
Hi Manuel,<br><br>This is a good optimization, but I worry about its implications on -Wunreachable-code.  We have a whole bunch of heuristics in -Wunreachable-code to not warn about dead code that is really only conditionally dead because of platform-specific constants.  For example:<br>
<br> <span> </span>if (sizeof(foo) > 4) { /* possibly dead; -Wunreachable-code doesn't warn */ )<br><br>To model this in the CFG, we actually still add the successors, but mark them as being possibly unreachable.  For example, here is some code elsewhere in CFG.cpp:<br>
<br> <span> </span>addSuccessor(Block, ThenBlock, /* isReachable = */ !KnownVal.isFalse());<br> <span> </span>addSuccessor(Block, ElseBlock, /* isReachable = */ !KnownVal.isTrue());<br><br>What happens is that most clients of the CFG see that the branch is dead, but other clients can recover the original edge.  By just outright pruning the edge we lose this information.  We want the same heuristics for dead code warnings to apply to ternary operators as well.  Instead of doing an early return, can you just use this modified version of addSuccessor?<br>
</blockquote><div style="font-family:Helvetica;font-size:14px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">
<br></div><div style="font-family:Helvetica;font-size:14px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">
Ok, I have a current fix for a more obvious bug and will add tests for platform specific constants next. Otherwise also feel free to revert in the meantime if it breaks something for you...</div></div></blockquote></div><div>
<br></div></div>Thanks Manuel.<div><br><div>I don't think it is breaking anything; it will just introduce false positives for -Wunreachable-code that ideally we will want to plug soon.  I think the natural tests here would be to extend the -Wunreachable-code test cases with more examples of ternary operations, and how we don't warn on cases that truly rely on platform specific constants.  We already have examples of this already for 'if'.</div>
<div><br></div><div>The upshot is that we want the CFG to be able to retain some of the information for unreachable blocks as some analyses don't want to see the pruning.  It's a fundamental design shift we introduced in the analyzer 4-5 months ago.  Before we just hard pruned branches.</div>
</div></div></blockquote></div><br></div><div class="gmail_extra">I actually think I have added all the tests already, and just have to flip them to not warn :)</div></div>