diff options
-rw-r--r-- | include/clang/Checker/PathSensitive/GRCoreEngine.h | 3 | ||||
-rw-r--r-- | lib/Checker/GRExprEngine.cpp | 6 | ||||
-rw-r--r-- | test/Analysis/misc-ps.m | 11 |
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}} +} + |