]> granicus.if.org Git - clang/commitdiff
SimpleConstraintManager doesn't reason about bitwise-constraints on symbolic
authorTed Kremenek <kremenek@apple.com>
Wed, 11 Mar 2009 02:29:48 +0000 (02:29 +0000)
committerTed Kremenek <kremenek@apple.com>
Wed, 11 Mar 2009 02:29:48 +0000 (02:29 +0000)
values. Indicating this in 'canReasonAbout' allows GRExprEngine to recover
path-sensitivity in some cases.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66628 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/SimpleConstraintManager.cpp
test/Analysis/misc-ps.m

index 82cc0bb7bc2ba89a7a6eb968702221f468247fbf..a4d59bec887381ecc6b880ef0b56b798fd1d7f54 100644 (file)
@@ -21,6 +21,19 @@ namespace clang {
 SimpleConstraintManager::~SimpleConstraintManager() {}
 
 bool SimpleConstraintManager::canReasonAbout(SVal X) const {
+  if (nonloc::SymIntConstraintVal *Y = dyn_cast<nonloc::SymIntConstraintVal>(&X)) {
+    const SymIntConstraint& C = Y->getConstraint();
+    switch (C.getOpcode()) {
+        // We don't reason yet about bitwise-constraints on symbolic values.
+      case BinaryOperator::And:
+      case BinaryOperator::Or:
+      case BinaryOperator::Xor:
+        return false;
+      default:
+        return true;
+    }
+  }
+
   return true;
 }
   
index 20a14f95c21295aa99cf7a6b5f5f0d3cfe83aa9e..04e6555dd1b219478a58b33a0874f27669563a96 100644 (file)
@@ -165,3 +165,16 @@ my_test_mm_movepi64_pi64(__a128vector a) {
 }
 @end
 
+// PR 3770
+char pr3770(int x) {
+  int y = x & 0x2;
+  char *p = 0;
+  if (y == 1)
+    p = "hello";
+
+  if (y == 1)
+    return p[0]; // no-warning
+    
+  return 'a';
+}
+