]> granicus.if.org Git - clang/commitdiff
Implicitly compare symbolic expressions to zero when they're being used as constraint...
authorJordy Rose <jediknil@belkadan.com>
Sun, 27 Jun 2010 01:20:56 +0000 (01:20 +0000)
committerJordy Rose <jediknil@belkadan.com>
Sun, 27 Jun 2010 01:20:56 +0000 (01:20 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@106972 91177308-0d34-0410-b5e6-96231b3b80d8

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

index a1594a9e9eeed2d962ae5a2a4c986135a51eb50f..321381b045ad35c2a6c422b478a571082774b050 100644 (file)
@@ -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)
index 1beb464cd1c0b3ca3481c2c7ce6d182fed7e3c43..0de5113072d5e3ada88d63b50c8eab95efe7221d 100644 (file)
@@ -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
+  }
+}
+