aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJordy Rose <jediknil@belkadan.com>2010-06-27 01:20:56 +0000
committerJordy Rose <jediknil@belkadan.com>2010-06-27 01:20:56 +0000
commit5ca129c2558a13d7d4b2b76fee8404bc07466ce9 (patch)
tree2f60aac8e0282aab78e48cbb816e3f731b0fd779
parentf70d857cbd79b24cb69f4990e31175e95e679a31 (diff)
Implicitly compare symbolic expressions to zero when they're being used as constraints. Part of PR7491.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@106972 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Checker/SimpleConstraintManager.cpp10
-rw-r--r--test/Analysis/misc-ps.m18
2 files changed, 25 insertions, 3 deletions
diff --git a/lib/Checker/SimpleConstraintManager.cpp b/lib/Checker/SimpleConstraintManager.cpp
index a1594a9e9e..321381b045 100644
--- a/lib/Checker/SimpleConstraintManager.cpp
+++ b/lib/Checker/SimpleConstraintManager.cpp
@@ -174,9 +174,13 @@ const GRState *SimpleConstraintManager::AssumeAux(const GRState *state,
return state;
BinaryOperator::Opcode op = SE->getOpcode();
- // FIXME: We should implicitly compare non-comparison expressions to 0.
- if (!BinaryOperator::isComparisonOp(op))
- return state;
+ // Implicitly compare non-comparison expressions to 0.
+ if (!BinaryOperator::isComparisonOp(op)) {
+ QualType T = SymMgr.getType(SE);
+ const llvm::APSInt &zero = BasicVals.getValue(0, T);
+ op = (Assumption ? BinaryOperator::NE : BinaryOperator::EQ);
+ return AssumeSymRel(state, SE, op, zero);
+ }
// From here on out, op is the real comparison we'll be testing.
if (!Assumption)
diff --git a/test/Analysis/misc-ps.m b/test/Analysis/misc-ps.m
index 1beb464cd1..0de5113072 100644
--- a/test/Analysis/misc-ps.m
+++ b/test/Analysis/misc-ps.m
@@ -981,3 +981,21 @@ void r7979430(id x) {
MAKE_TEST_FN() // expected-warning{{null pointer}}
+//===----------------------------------------------------------------------===
+// PR 7491 - Test that symbolic expressions can be used as conditions.
+//===----------------------------------------------------------------------===
+
+void pr7491 () {
+ extern int getint();
+ int a = getint()-1;
+ if (a) {
+ return;
+ }
+ if (!a) {
+ return;
+ } else {
+ // Should be unreachable
+ (void)*(char*)0; // no-warning
+ }
+}
+