summaryrefslogtreecommitdiff
path: root/lib/Analysis/ReachableCode.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2014-03-06 01:09:45 +0000
committerTed Kremenek <kremenek@apple.com>2014-03-06 01:09:45 +0000
commitf09edf7292998f3e93f8026005bc544cb8f34178 (patch)
treeedbad03dcd3b3edf7fcf918815028daea43e81e6 /lib/Analysis/ReachableCode.cpp
parentb182cdf142ecce079c19aea8981309237a78202f (diff)
downloadclang-f09edf7292998f3e93f8026005bc544cb8f34178.tar.gz
[-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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@203051 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/ReachableCode.cpp')
-rw-r--r--lib/Analysis/ReachableCode.cpp11
1 files changed, 4 insertions, 7 deletions
diff --git a/lib/Analysis/ReachableCode.cpp b/lib/Analysis/ReachableCode.cpp
index 9f6792e2cc..8b192d2d61 100644
--- a/lib/Analysis/ReachableCode.cpp
+++ b/lib/Analysis/ReachableCode.cpp
@@ -312,7 +312,8 @@ static bool isTrivialReturnOrDoWhile(const CFGBlock *B, const Stmt *S) {
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 @@ static bool isTrivialReturnOrDoWhile(const CFGBlock *B, const Stmt *S) {
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;
}