summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2014-03-15 06:47:45 +0000
committerTed Kremenek <kremenek@apple.com>2014-03-15 06:47:45 +0000
commit9dfe400dc23a73847807a103c0020cf5c38a9820 (patch)
tree82acc03c7a89682a2b499a65f154e321a41873ed
parentad8753c00eac02acf9ef30aceb316721abf7ef6c (diff)
downloadbcm5719-llvm-9dfe400dc23a73847807a103c0020cf5c38a9820.tar.gz
bcm5719-llvm-9dfe400dc23a73847807a103c0020cf5c38a9820.zip
-Wunreachable-code: treat 'const bool' locals as control values.
llvm-svn: 204001
-rw-r--r--clang/lib/Analysis/ReachableCode.cpp7
-rw-r--r--clang/test/SemaCXX/warn-unreachable.cpp19
2 files changed, 25 insertions, 1 deletions
diff --git a/clang/lib/Analysis/ReachableCode.cpp b/clang/lib/Analysis/ReachableCode.cpp
index d297d03775d..71d41bb2839 100644
--- a/clang/lib/Analysis/ReachableCode.cpp
+++ b/clang/lib/Analysis/ReachableCode.cpp
@@ -236,7 +236,12 @@ static bool isConfigurationValue(const Stmt *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;
}
diff --git a/clang/test/SemaCXX/warn-unreachable.cpp b/clang/test/SemaCXX/warn-unreachable.cpp
index 17f0b9bf528..2370fe0da24 100644
--- a/clang/test/SemaCXX/warn-unreachable.cpp
+++ b/clang/test/SemaCXX/warn-unreachable.cpp
@@ -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;
+}
+
OpenPOWER on IntegriCloud