[cfe-commits] r67534 - in /cfe/trunk: lib/Analysis/SimpleConstraintManager.cpp test/Analysis/retain-release.m

Ted Kremenek kremenek at apple.com
Mon Mar 23 10:10:28 PDT 2009


Author: kremenek
Date: Mon Mar 23 12:10:25 2009
New Revision: 67534

URL: http://llvm.org/viewvc/llvm-project?rev=67534&view=rev
Log:
analyzer: Provide temporary workaround for false positive reported by
<rdar://problem/6704930> involving SimpleConstraintManager not reasoning well
about symbolic constraint values involving arithmetic operators.

Modified:
    cfe/trunk/lib/Analysis/SimpleConstraintManager.cpp
    cfe/trunk/test/Analysis/retain-release.m

Modified: cfe/trunk/lib/Analysis/SimpleConstraintManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/SimpleConstraintManager.cpp?rev=67534&r1=67533&r2=67534&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/SimpleConstraintManager.cpp (original)
+++ cfe/trunk/lib/Analysis/SimpleConstraintManager.cpp Mon Mar 23 12:10:25 2009
@@ -29,6 +29,17 @@
       case BinaryOperator::Or:
       case BinaryOperator::Xor:
         return false;
+        // We don't reason yet about arithmetic constraints on symbolic values.
+      case BinaryOperator::Mul:
+      case BinaryOperator::Div:
+      case BinaryOperator::Rem:
+      case BinaryOperator::Add:
+      case BinaryOperator::Sub:
+      case BinaryOperator::Shl:
+      case BinaryOperator::Shr:
+        return false;
+
+        // All other cases.
       default:
         return true;
     }

Modified: cfe/trunk/test/Analysis/retain-release.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/retain-release.m?rev=67534&r1=67533&r2=67534&view=diff

==============================================================================
--- cfe/trunk/test/Analysis/retain-release.m (original)
+++ cfe/trunk/test/Analysis/retain-release.m Mon Mar 23 12:10:25 2009
@@ -299,8 +299,8 @@
   NSString *kind = [[NSString alloc] initWithUTF8String:inkind];  // expected-warning{{leak}}
   
   // We do allow stringWithUTF8String to fail.  This isn't really correct, as
-  // far as returning nil.  In most error conditions it will throw an exception.
-  // If allocation fails it could return nil, but again this
+  // far as returning 0.  In most error conditions it will throw an exception.
+  // If allocation fails it could return 0, but again this
   // isn't expected.
   NSString *name = [NSString stringWithUTF8String:inname];
   if(!name)
@@ -360,3 +360,37 @@
   [foo dealloc]; // expected-warning{{used after it is released}}
   // message sent to released object
 }
+
+// From <rdar://problem/6704930>.  The problem here is that 'length' binds to
+// '($0 - 1)' after '--length', but SimpleConstraintManager doesn't know how to
+// reason about '($0 - 1) > constant'.  As a temporary hack, we drop the value
+// of '($0 - 1)' and conjure a new symbol.
+void rdar6704930(unsigned char *s, unsigned int length) {
+  NSString* name = 0;
+  if (s != 0) {
+    if (length > 0) {
+      while (length > 0) {
+        if (*s == ':') {
+          ++s;
+          --length;
+          name = [[NSString alloc] init]; // no-warning
+          break;
+        }
+        ++s;
+        --length;
+      }
+      if ((length == 0) && (name != 0)) {
+        [name release];
+        name = 0;
+      }
+      if (length == 0) { // no ':' found -> use it all as name
+        name = [[NSString alloc] init]; // no-warning
+      }
+    }
+  }
+
+  if (name != 0) {
+    [name release];
+  }
+}
+





More information about the cfe-commits mailing list