From: Ted Kremenek Date: Wed, 5 Mar 2014 23:38:41 +0000 (+0000) Subject: [-Wunreachable-code] include some enum constants in "configuration value" heuristic X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c33de64f80bcef9bdd3cd2573100be3b683afe7d;p=clang [-Wunreachable-code] include some enum constants in "configuration value" heuristic git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@203026 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/ReachableCode.cpp b/lib/Analysis/ReachableCode.cpp index f159642db2..b772145456 100644 --- a/lib/Analysis/ReachableCode.cpp +++ b/lib/Analysis/ReachableCode.cpp @@ -376,6 +376,11 @@ static bool isConfigurationValue(const Stmt *S) { S = Ex->IgnoreParenCasts(); switch (S->getStmtClass()) { + case Stmt::DeclRefExprClass: { + const DeclRefExpr *DR = cast(S); + const EnumConstantDecl *ED = dyn_cast(DR->getDecl()); + return ED ? isConfigurationValue(ED->getInitExpr()) : false; + } case Stmt::IntegerLiteralClass: return isExpandedFromConfigurationMacro(S); case Stmt::UnaryExprOrTypeTraitExprClass: diff --git a/test/Sema/warn-unreachable.c b/test/Sema/warn-unreachable.c index e8089aaa4f..a3c4985590 100644 --- a/test/Sema/warn-unreachable.c +++ b/test/Sema/warn-unreachable.c @@ -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; +} +