]> granicus.if.org Git - clang/commitdiff
Fix PR 3836 by eagerly assuming symbolic constraints returned by unary '!'.
authorTed Kremenek <kremenek@apple.com>
Wed, 18 Mar 2009 23:49:26 +0000 (23:49 +0000)
committerTed Kremenek <kremenek@apple.com>
Wed, 18 Mar 2009 23:49:26 +0000 (23:49 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67260 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/GRExprEngine.cpp
test/Analysis/misc-ps-eager-assume.m

index 6d360ed5033c726f8c1d0bdb0bff71cad7058790..1f47bc7f331270cd80d03818a97129fb4f47fece 100644 (file)
@@ -394,9 +394,17 @@ void GRExprEngine::Visit(Stmt* S, NodeTy* Pred, NodeSet& Dst) {
       VisitLValue(cast<StringLiteral>(S), Pred, Dst);
       break;
       
-    case Stmt::UnaryOperatorClass:
-      VisitUnaryOperator(cast<UnaryOperator>(S), Pred, Dst, false);
+    case Stmt::UnaryOperatorClass: {
+      UnaryOperator *U = cast<UnaryOperator>(S);
+      if (EagerlyAssume && (U->getOpcode() == UnaryOperator::LNot)) {
+        NodeSet Tmp;
+        VisitUnaryOperator(U, Pred, Tmp, false);
+        EvalEagerlyAssume(Dst, Tmp, U);
+      }
+      else
+        VisitUnaryOperator(U, Pred, Dst, false);
       break;
+    }
   }
 }
 
index c36ae8f4d639205ea46c7accd48b6208def50fff..4dd8f2536c484785d0007dcd3cfc893ac461ccfe 100644 (file)
@@ -61,3 +61,19 @@ void handle_symbolic_cast_in_condition(void) {
 
   [pool drain];
 }
+
+// From PR 3836 (http://llvm.org/bugs/show_bug.cgi?id=3836)
+//
+// In this test case, the double '!' works fine with our symbolic constraints,
+// but we don't support comparing SymConstraint != SymConstraint.  By eagerly
+// assuming the truth of !!a or !!b, we can compare these values directly.
+//
+void pr3836(int *a, int *b) {
+  if (!!a != !!b) /* one of them is NULL */
+    return;
+  if (!a && !b) /* both are NULL */
+    return;
+      
+  *a = 1; // no-warning
+  *b = 1; // no-warning
+}