]> granicus.if.org Git - clang/commitdiff
Fix horrible GRExprEngine bug where switch statements with no 'case:' statements...
authorTed Kremenek <kremenek@apple.com>
Thu, 26 Aug 2010 22:19:33 +0000 (22:19 +0000)
committerTed Kremenek <kremenek@apple.com>
Thu, 26 Aug 2010 22:19:33 +0000 (22:19 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@112233 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Checker/PathSensitive/GRCoreEngine.h
lib/Checker/GRExprEngine.cpp
test/Analysis/misc-ps.m

index 4f9f2d811c15770e56613de5ffc75a8744110138..216ecac73653195c23748c6b10e6473545a6b221 100644 (file)
@@ -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());
index 3578483a82913952cb55ed5f35df115aeed8f312..c9173aa92afe5780a25bcd61e5eb2dfa3880351c 100644 (file)
@@ -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.
index b4fa77ef3e78a37432a215ec4024cbb0a9d03e33..ced0853574d3d40d9489f277b9d8288f49c5ce99 100644 (file)
@@ -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}}
+}
+