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
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
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;
}
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) {
// 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;
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) {