summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/Analysis/ReachableCode.cpp11
-rw-r--r--test/Sema/warn-unreachable.c3
-rw-r--r--test/SemaCXX/unreachable-code.cpp16
3 files changed, 20 insertions, 10 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;
}
diff --git a/test/Sema/warn-unreachable.c b/test/Sema/warn-unreachable.c
index bf1e9137eb..fe47e4c6b7 100644
--- a/test/Sema/warn-unreachable.c
+++ b/test/Sema/warn-unreachable.c
@@ -209,9 +209,10 @@ MyEnum trivial_dead_return_enum_2(int x) {
case 1: return 1;
case 2: return 2;
case 3: return 3;
+ default: return 4;
}
- return 2; // no-warning
+ return 2; // expected-warning {{will never be executed}}
}
MyEnum nontrivial_dead_return_enum_2(int x) {
diff --git a/test/SemaCXX/unreachable-code.cpp b/test/SemaCXX/unreachable-code.cpp
index 743290e1b9..b6b8ab4209 100644
--- a/test/SemaCXX/unreachable-code.cpp
+++ b/test/SemaCXX/unreachable-code.cpp
@@ -1,7 +1,7 @@
// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -Wunreachable-code -fblocks -verify %s
int j;
-void bar() { }
+int bar();
int test1() {
for (int i = 0;
i != 10;
@@ -11,7 +11,19 @@ int test1() {
return 1;
}
return 0;
- return 1; // expected-warning {{will never be executed}}
+ return 1; // expected-warning {{will never be executed}}
+}
+
+int test1_B() {
+ for (int i = 0;
+ i != 10;
+ ++i) { // expected-warning {{will never be executed}}
+ if (j == 23) // missing {}'s
+ bar();
+ return 1;
+ }
+ return 0;
+ return bar(); // expected-warning {{will never be executed}}
}
void test2(int i) {