summaryrefslogtreecommitdiffstats
path: root/clang
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
commit7f8ea4d677f2c07f281d0fe3c67895fe1cb93999 (patch)
treefbced1b1f60500a6e66d46a19d1a6e1c9c398d57 /clang
parente01d966ce22e90a3d007bbb60a88c6b553bb74b5 (diff)
downloadbcm5719-llvm-7f8ea4d677f2c07f281d0fe3c67895fe1cb93999.tar.gz
bcm5719-llvm-7f8ea4d677f2c07f281d0fe3c67895fe1cb93999.zip
Implicitly compare symbolic expressions to zero when they're being used as constraints. Part of PR7491.
llvm-svn: 106972
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/Checker/SimpleConstraintManager.cpp10
-rw-r--r--clang/test/Analysis/misc-ps.m18
2 files changed, 25 insertions, 3 deletions
diff --git a/clang/lib/Checker/SimpleConstraintManager.cpp b/clang/lib/Checker/SimpleConstraintManager.cpp
index a1594a9e9ee..321381b045a 100644
--- a/clang/lib/Checker/SimpleConstraintManager.cpp
+++ b/clang/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/clang/test/Analysis/misc-ps.m b/clang/test/Analysis/misc-ps.m
index 1beb464cd1c..0de5113072d 100644
--- a/clang/test/Analysis/misc-ps.m
+++ b/clang/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
+ }
+}
+
OpenPOWER on IntegriCloud