r203026 - [-Wunreachable-code] include some enum constants in "configuration value" heuristic
Ted Kremenek
kremenek at apple.com
Wed Mar 5 15:38:41 PST 2014
Author: kremenek
Date: Wed Mar 5 17:38:41 2014
New Revision: 203026
URL: http://llvm.org/viewvc/llvm-project?rev=203026&view=rev
Log:
[-Wunreachable-code] include some enum constants in "configuration value" heuristic
Modified:
cfe/trunk/lib/Analysis/ReachableCode.cpp
cfe/trunk/test/Sema/warn-unreachable.c
Modified: cfe/trunk/lib/Analysis/ReachableCode.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/ReachableCode.cpp?rev=203026&r1=203025&r2=203026&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/ReachableCode.cpp (original)
+++ cfe/trunk/lib/Analysis/ReachableCode.cpp Wed Mar 5 17:38:41 2014
@@ -376,6 +376,11 @@ static bool isConfigurationValue(const 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:
Modified: cfe/trunk/test/Sema/warn-unreachable.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-unreachable.c?rev=203026&r1=203025&r2=203026&view=diff
==============================================================================
--- cfe/trunk/test/Sema/warn-unreachable.c (original)
+++ cfe/trunk/test/Sema/warn-unreachable.c Wed Mar 5 17:38:41 2014
@@ -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;
+}
+
More information about the cfe-commits
mailing list