SimpleConstraintManager doesn't reason about bitwise-constraints on symbolic
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
diff --git a/lib/Analysis/SimpleConstraintManager.cpp b/lib/Analysis/SimpleConstraintManager.cpp
index 82cc0bb..a4d59be 100644
--- a/lib/Analysis/SimpleConstraintManager.cpp
+++ b/lib/Analysis/SimpleConstraintManager.cpp
@@ -21,6 +21,19 @@
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;
}
diff --git a/test/Analysis/misc-ps.m b/test/Analysis/misc-ps.m
index 20a14f9..04e6555 100644
--- a/test/Analysis/misc-ps.m
+++ b/test/Analysis/misc-ps.m
@@ -165,3 +165,16 @@
}
@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';
+}
+