<div dir="ltr">Ping.</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, May 7, 2014 at 12:10 PM, Manuel Klimek <span dir="ltr"><<a href="mailto:klimek@google.com" target="_blank">klimek@google.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Wordsmithing.<br>
<div><div class="h5"><br>
<a href="http://reviews.llvm.org/D3638" target="_blank">http://reviews.llvm.org/D3638</a><br>
<br>
Files:<br>
lib/Analysis/ReachableCode.cpp<br>
<br>
Index: lib/Analysis/ReachableCode.cpp<br>
===================================================================<br>
--- lib/Analysis/ReachableCode.cpp<br>
+++ lib/Analysis/ReachableCode.cpp<br>
@@ -59,32 +59,57 @@<br>
}<br>
<br>
static bool isDeadReturn(const CFGBlock *B, const Stmt *S) {<br>
- // Look to see if the block ends with a 'return', and see if 'S'<br>
- // is a substatement. The 'return' may not be the last element in<br>
- // the block because of destructors.<br>
- for (CFGBlock::const_reverse_iterator I = B->rbegin(), E = B->rend();<br>
- I != E; ++I) {<br>
- if (Optional<CFGStmt> CS = I->getAs<CFGStmt>()) {<br>
- if (const ReturnStmt *RS = dyn_cast<ReturnStmt>(CS->getStmt())) {<br>
- if (RS == S)<br>
- return true;<br>
- if (const Expr *RE = RS->getRetValue()) {<br>
- RE = RE->IgnoreParenCasts();<br>
- if (RE == S)<br>
+ // Look to see if the current control flow ends with a 'return', and see if<br>
+ // 'S' is a substatement. The 'return' may not be the last element in the<br>
+ // block, or may be in a subsequent block because of destructors.<br>
+ const CFGBlock *Current = B;<br>
+ while (true) {<br>
+ for (CFGBlock::const_reverse_iterator I = Current->rbegin(),<br>
+ E = Current->rend();<br>
+ I != E; ++I) {<br>
+ if (Optional<CFGStmt> CS = I->getAs<CFGStmt>()) {<br>
+ if (const ReturnStmt *RS = dyn_cast<ReturnStmt>(CS->getStmt())) {<br>
+ if (RS == S)<br>
return true;<br>
- ParentMap PM(const_cast<Expr*>(RE));<br>
- // If 'S' is in the ParentMap, it is a subexpression of<br>
- // the return statement. Note also that we are restricting<br>
- // to looking at return statements in the same CFGBlock,<br>
- // so this will intentionally not catch cases where the<br>
- // return statement contains nested control-flow.<br>
- return PM.getParent(S);<br>
+ if (const Expr *RE = RS->getRetValue()) {<br>
+ RE = RE->IgnoreParenCasts();<br>
+ if (RE == S)<br>
+ return true;<br>
+ ParentMap PM(const_cast<Expr *>(RE));<br>
+ // If 'S' is in the ParentMap, it is a subexpression of<br>
+ // the return statement.<br>
+ return PM.getParent(S);<br>
+ }<br>
}<br>
+ break;<br>
+ }<br>
+ }<br>
+ // Note also that we are restricting the search for the return statement<br>
</div></div>+ // to stop at control-flow; only part of a return statement may be dead,<br>
<div class="">+ // without the whole return statement being dead.<br>
+ if (Current->getTerminator().isTemporaryDtorsBranch()) {<br>
</div>+ // Temporary destructors have a predictable control flow, thus we want to<br>
+ // look into the next block for the return statement.<br>
<div class="HOEnZb"><div class="h5">+ // We look into the false branch, as we know the true branch only contains<br>
+ // the call to the destructor.<br>
+ assert(Current->succ_size() == 2);<br>
+ Current = *(Current->succ_begin() + 1);<br>
+ } else if (!Current->getTerminator() && Current->succ_size() == 1) {<br>
+ // If there is only one successor, we're not dealing with outgoing control<br>
+ // flow. Thus, look into the next block.<br>
+ Current = *Current->succ_begin();<br>
+ if (Current->pred_size() > 1) {<br>
+ // If there is more than one predecessor, we're dealing with incoming<br>
+ // control flow - if the return statement is in that block, it might<br>
+ // well be reachable via a different control flow, thus it's not dead.<br>
+ return false;<br>
}<br>
- break;<br>
+ } else {<br>
+ // We hit control flow or a dead end. Stop searching.<br>
+ return false;<br>
}<br>
}<br>
- return false;<br>
+ llvm_unreachable("Broke out of infinite loop.");<br>
}<br>
<br>
static SourceLocation getTopMostMacro(SourceLocation Loc, SourceManager &SM) {<br>
</div></div></blockquote></div><br></div>