[-Wunreachable-code] Handle idiomatic do...while() with an uninteresting condition.
Sometimes do..while() is used to create a scope that can be left early.
In such cases, the unreachable 'while()' test is not usually interesting
unless it actually does something that is observable.
llvm-svn: 203051
diff --git a/clang/lib/Analysis/ReachableCode.cpp b/clang/lib/Analysis/ReachableCode.cpp
index 9f6792e..8b192d2 100644
--- a/clang/lib/Analysis/ReachableCode.cpp
+++ b/clang/lib/Analysis/ReachableCode.cpp
@@ -312,7 +312,8 @@
return true;
}
-
+ if (B->pred_size() != 1)
+ return false;
// Look to see if the block ends with a 'return', and see if 'S'
// is a substatement. The 'return' may not be the last element in
@@ -324,15 +325,11 @@
if (const ReturnStmt *RS = dyn_cast<ReturnStmt>(CS->getStmt())) {
const Expr *RE = RS->getRetValue();
if (RE && RE->IgnoreParenCasts() == Ex)
- break;
+ return bodyEndsWithNoReturn(*B->pred_begin());
}
- return false;
+ break;
}
}
-
- if (B->pred_size() == 1)
- return bodyEndsWithNoReturn(*B->pred_begin());
-
return false;
}