]> granicus.if.org Git - clang/commitdiff
[-Wunreachable-code] include some enum constants in "configuration value" heuristic
authorTed Kremenek <kremenek@apple.com>
Wed, 5 Mar 2014 23:38:41 +0000 (23:38 +0000)
committerTed Kremenek <kremenek@apple.com>
Wed, 5 Mar 2014 23:38:41 +0000 (23:38 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@203026 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/ReachableCode.cpp
test/Sema/warn-unreachable.c

index f159642db2ffce5392a377d492305162e187e737..b772145456ee723dede38fc284d9708eb4c64b0e 100644 (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:
index e8089aaa4f9cf4d653db8c81409badb13d8db0ce..a3c498559059dc3ecd00d99abb5dbbec6c8dd798 100644 (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;
+}
+