r204001 - -Wunreachable-code: treat 'const bool' locals as control values.

Ted Kremenek kremenek at apple.com
Fri Mar 14 23:47:45 PDT 2014


Author: kremenek
Date: Sat Mar 15 01:47:45 2014
New Revision: 204001

URL: http://llvm.org/viewvc/llvm-project?rev=204001&view=rev
Log:
-Wunreachable-code: treat 'const bool' locals as control values.

Modified:
    cfe/trunk/lib/Analysis/ReachableCode.cpp
    cfe/trunk/test/SemaCXX/warn-unreachable.cpp

Modified: cfe/trunk/lib/Analysis/ReachableCode.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/ReachableCode.cpp?rev=204001&r1=204000&r2=204001&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/ReachableCode.cpp (original)
+++ cfe/trunk/lib/Analysis/ReachableCode.cpp Sat Mar 15 01:47:45 2014
@@ -236,7 +236,12 @@ static bool isConfigurationValue(const S
         // We could generalize this to local variables, but it isn't
         // clear if those truly represent configuration values that
         // gate unreachable code.
-        return !VD->hasLocalStorage();
+        if (!VD->hasLocalStorage())
+          return true;
+
+        // As a heuristic, locals that have been marked 'const' explicitly
+        // can be treated as configuration values as well.
+        return VD->getType().isLocalConstQualified();
       }
       return false;
     }

Modified: cfe/trunk/test/SemaCXX/warn-unreachable.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-unreachable.cpp?rev=204001&r1=204000&r2=204001&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-unreachable.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-unreachable.cpp Sat Mar 15 01:47:45 2014
@@ -199,3 +199,22 @@ int test_arithmetic() {
   return 2; // expected-warning {{never be executed}}
 }
 
+int test_treat_const_bool_local_as_config_value() {
+  const bool controlValue = false;
+  if (!controlValue)
+    return 1;
+  test_treat_const_bool_local_as_config_value(); // no-warning
+  return 0;
+}
+
+int test_treat_non_const_bool_local_as_non_config_value() {
+  bool controlValue = false;
+  if (!controlValue)
+    return 1;
+  // There is no warning here because 'controlValue' isn't really
+  // a control value at all.  The CFG will not treat this
+  // branch as unreachable.
+  test_treat_non_const_bool_local_as_non_config_value(); // no-warning
+  return 0;
+}
+





More information about the cfe-commits mailing list