[-Wunreachable-code] include some enum constants in "configuration value" heuristic

llvm-svn: 203026
This commit is contained in:
Ted Kremenek 2014-03-05 23:38:41 +00:00
parent da3f4fd3fe
commit 01a39b601f
2 changed files with 23 additions and 0 deletions

View File

@ -376,6 +376,11 @@ static bool isConfigurationValue(const Stmt *S) {
S = Ex->IgnoreParenCasts();
switch (S->getStmtClass()) {
case Stmt::DeclRefExprClass: {
const DeclRefExpr *DR = cast<DeclRefExpr>(S);
const EnumConstantDecl *ED = dyn_cast<EnumConstantDecl>(DR->getDecl());
return ED ? isConfigurationValue(ED->getInitExpr()) : false;
}
case Stmt::IntegerLiteralClass:
return isExpandedFromConfigurationMacro(S);
case Stmt::UnaryExprOrTypeTraitExprClass:

View File

@ -234,3 +234,21 @@ int sizeof_int() {
return 2; // no-warning
}
enum MyEnum {
ME_A = CONFIG_CONSTANT,
ME_B = 1
};
int test_MyEnum() {
if (!ME_A)
return 1; // no-warning
if (ME_A)
return 2; // no-warning
if (ME_B)
return 3;
// FIXME: we should only need one diagnostic here.
if (!ME_B) // expected-warning {{will never be executed}}
return 4;// expected-warning {{will never be executed}}
return 5;
}