summaryrefslogtreecommitdiffstats
path: root/clang/lib/Analysis/ReachableCode.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2014-03-08 02:22:23 +0000
committerTed Kremenek <kremenek@apple.com>2014-03-08 02:22:23 +0000
commit04bfbeea04f722aa2eca6677c90460404a8f71bd (patch)
tree3788e349fa44c6ffb0e4d22c0b86a3f817c261a5 /clang/lib/Analysis/ReachableCode.cpp
parent53b8ea1c89c9a0f82832f709264f492983d43a29 (diff)
downloadbcm5719-llvm-04bfbeea04f722aa2eca6677c90460404a8f71bd.tar.gz
bcm5719-llvm-04bfbeea04f722aa2eca6677c90460404a8f71bd.zip
[-Wunreachable-code] Handle 'return' with no argument dominated by 'noreturn' function.
llvm-svn: 203333
Diffstat (limited to 'clang/lib/Analysis/ReachableCode.cpp')
-rw-r--r--clang/lib/Analysis/ReachableCode.cpp17
1 files changed, 11 insertions, 6 deletions
diff --git a/clang/lib/Analysis/ReachableCode.cpp b/clang/lib/Analysis/ReachableCode.cpp
index 47f8f2b90cd..5d74156092c 100644
--- a/clang/lib/Analysis/ReachableCode.cpp
+++ b/clang/lib/Analysis/ReachableCode.cpp
@@ -132,10 +132,8 @@ static bool isTrivialExpression(const Expr *Ex) {
static bool isTrivialReturnOrDoWhile(const CFGBlock *B, const Stmt *S) {
const Expr *Ex = dyn_cast<Expr>(S);
- if (!Ex)
- return false;
- if (!isTrivialExpression(Ex))
+ if (Ex && !isTrivialExpression(Ex))
return false;
// Check if the block ends with a do...while() and see if 'S' is the
@@ -152,13 +150,20 @@ static bool isTrivialReturnOrDoWhile(const CFGBlock *B, const Stmt *S) {
// 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
// the block because of destructors.
- assert(!B->empty());
for (CFGBlock::const_reverse_iterator I = B->rbegin(), E = B->rend();
I != E; ++I) {
if (Optional<CFGStmt> CS = I->getAs<CFGStmt>()) {
if (const ReturnStmt *RS = dyn_cast<ReturnStmt>(CS->getStmt())) {
- const Expr *RE = RS->getRetValue();
- if (RE && stripExprSugar(RE->IgnoreParenCasts()) == Ex)
+ bool LookAtBody = false;
+ if (RS == S)
+ LookAtBody = true;
+ else {
+ const Expr *RE = RS->getRetValue();
+ if (RE && stripExprSugar(RE->IgnoreParenCasts()) == Ex)
+ LookAtBody = true;
+ }
+
+ if (LookAtBody)
return bodyEndsWithNoReturn(*B->pred_begin());
}
break;
OpenPOWER on IntegriCloud