From 34feff654c6304e0a59ceb1376989d28dbc956ff Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Thu, 26 Aug 2010 22:19:33 +0000 Subject: [PATCH] Fix horrible GRExprEngine bug where switch statements with no 'case:' statements would cause the path to get prematurely aborted. Fixes . git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@112233 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Checker/PathSensitive/GRCoreEngine.h | 3 ++- lib/Checker/GRExprEngine.cpp | 6 ++++-- 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((*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(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 } + +// - 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}} +} + -- 2.40.0