aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2010-08-26 22:19:33 +0000
committerTed Kremenek <kremenek@apple.com>2010-08-26 22:19:33 +0000
commit34feff654c6304e0a59ceb1376989d28dbc956ff (patch)
tree9e8d481dc6ce771979bfd42559f1d68e7f75d588
parent412711774cf912bac8e81ef86da33acac6856b8a (diff)
Fix horrible GRExprEngine bug where switch statements with no 'case:' statements would cause the path to get prematurely aborted. Fixes <rdar://problem/8360854>.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@112233 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Checker/PathSensitive/GRCoreEngine.h3
-rw-r--r--lib/Checker/GRExprEngine.cpp6
-rw-r--r--test/Analysis/misc-ps.m11
3 files changed, 17 insertions, 3 deletions
diff --git a/include/clang/Checker/PathSensitive/GRCoreEngine.h b/include/clang/Checker/PathSensitive/GRCoreEngine.h
index 4f9f2d811c..216ecac736 100644
--- a/include/clang/Checker/PathSensitive/GRCoreEngine.h
+++ b/include/clang/Checker/PathSensitive/GRCoreEngine.h
@@ -407,7 +407,8 @@ public:
public:
iterator& operator++() { ++I; return *this; }
- bool operator!=(const iterator& X) const { return I != X.I; }
+ bool operator!=(const iterator &X) const { return I != X.I; }
+ bool operator==(const iterator &X) const { return I == X.I; }
const CaseStmt* getCase() const {
return llvm::cast<CaseStmt>((*I)->getLabel());
diff --git a/lib/Checker/GRExprEngine.cpp b/lib/Checker/GRExprEngine.cpp
index 3578483a82..c9173aa92a 100644
--- a/lib/Checker/GRExprEngine.cpp
+++ b/lib/Checker/GRExprEngine.cpp
@@ -1489,9 +1489,11 @@ void GRExprEngine::ProcessSwitch(GRSwitchNodeBuilder& builder) {
DefinedOrUnknownSVal CondV = cast<DefinedOrUnknownSVal>(CondV_untested);
const GRState *DefaultSt = state;
- bool defaultIsFeasible = false;
+
+ iterator I = builder.begin(), EI = builder.end();
+ bool defaultIsFeasible = I == EI;
- for (iterator I = builder.begin(), EI = builder.end(); I != EI; ++I) {
+ for ( ; I != EI; ++I) {
const CaseStmt* Case = I.getCase();
// Evaluate the LHS of the case value.
diff --git a/test/Analysis/misc-ps.m b/test/Analysis/misc-ps.m
index b4fa77ef3e..ced0853574 100644
--- a/test/Analysis/misc-ps.m
+++ b/test/Analysis/misc-ps.m
@@ -1045,3 +1045,14 @@ void reduce_to_constant(int x, int y) {
if (y == -20 && b != 0)
(void)*(char*)0; // no-warning
}
+
+// <rdar://problem/8360854> - Test that code after a switch statement with no
+// 'case:' labels is correctly evaluated.
+void r8360854(int n) {
+ switch (n) {
+ default: ;
+ }
+ int *p = 0;
+ *p = 0xDEADBEEF; // expected-warning{{null pointer}}
+}
+