Esempio n. 1
0
int main() {
  VC vc = vc_createValidityChecker(NULL);

  /* Prove that for integers x and y:
   *   x > 0 AND y > 0  =>  2x + y >= 3 */

  Type integer = vc_intType(vc);

  Expr x = vc_varExpr(vc, "x", integer);
  Expr y = vc_varExpr(vc, "y", integer);
  Expr zero = vc_ratExpr(vc, 0, 1);

  Expr x_positive = vc_gtExpr(vc, x, zero);
  Expr y_positive = vc_gtExpr(vc, y, zero);

  Expr two = vc_ratExpr(vc, 2, 1);
  Expr twox = vc_multExpr(vc, two, x);
  Expr twox_plus_y = vc_plusExpr(vc, twox, y);

  Expr three = vc_ratExpr(vc, 3, 1);
  Expr twox_plus_y_geq_3 = vc_geExpr(vc, twox_plus_y, three);

  Expr formula = vc_impliesExpr(vc, vc_andExpr(vc, x_positive, y_positive),
                                twox_plus_y_geq_3);

  char* formulaString = vc_printExprString(vc, formula);

  printf("Checking validity of formula %s with CVC4.\n", formulaString);
  printf("CVC4 should return 1 (meaning VALID).\n");
  printf("Result from CVC4 is: %d\n", vc_query(vc, formula));

  free(formulaString);

  return 0;
}
Esempio n. 2
0
TEST(Leaks, boolean)
{
  VC vc;
  vc = vc_createValidityChecker();

  Expr x = vc_varExpr(vc, "x", vc_boolType(vc));
  Expr y = vc_varExpr(vc, "y", vc_boolType(vc));

  Expr x_and_y = vc_andExpr(vc, x, y);
  Expr not_x_and_y = vc_notExpr(vc, x_and_y);

  Expr not_x = vc_notExpr(vc, x);
  Expr not_y = vc_notExpr(vc, y);
  Expr not_x_or_not_y = vc_orExpr(vc, not_x, not_y);

  Expr equiv = vc_iffExpr(vc, not_x_and_y, not_x_or_not_y);

  printf("%d\n", vc_query(vc, equiv));

  vc_DeleteExpr(equiv);
  vc_DeleteExpr(not_x_or_not_y);
  vc_DeleteExpr(not_y);
  vc_DeleteExpr(not_x);
  vc_DeleteExpr(not_x_and_y);
  vc_DeleteExpr(x_and_y);
  vc_DeleteExpr(y);
  vc_DeleteExpr(x);
  vc_Destroy(vc);
}
Esempio n. 3
0
// FIXME: Pick a sensible testname that actually means something!
TEST(array_cvcl02,one) {
  VC vc = vc_createValidityChecker();
  vc_setFlag(vc,'n');
  vc_setFlag(vc,'d');
  vc_setFlag(vc,'p');

  Expr cvcl_array = vc_varExpr1(vc, "a",32,32);
  Expr i = vc_varExpr1(vc, "i", 0, 8);   
  Expr i32 = vc_bvConcatExpr(vc,
 			     vc_bvConstExprFromStr(vc,
 						   "000000000000000000000000"),
 			     i); 
  Expr no_underflow = vc_bvLeExpr(vc,
				  vc_bvConstExprFromInt(vc, 32, 0),
				  i32);  
  Expr no_overflow = vc_bvLeExpr(vc,
				 i32,
				 vc_bvConstExprFromInt(vc, 32, 9));  
  Expr in_bounds = vc_andExpr(vc, no_underflow, no_overflow);  
  Expr a_of_i = vc_bvSignExtend(vc,
				vc_readExpr(vc,cvcl_array,i32),
				32);  
  Expr a_of_i_eq_11 = vc_eqExpr(vc, 
				vc_bvConcatExpr(vc,i32,a_of_i),
				vc_bvConstExprFromInt(vc, 64, 11));
 
  vc_assertFormula(vc, in_bounds);
  vc_assertFormula(vc, a_of_i_eq_11);  
  vc_query(vc, vc_falseExpr(vc));

  long long v; 
  Expr pre = vc_bvConstExprFromInt(vc,24,0);
  int j;
  for(j=0;j<10;j++) {
    Expr exprj = vc_bvConstExprFromInt(vc,8,j);
    Expr index = vc_bvConcatExpr(vc, pre, exprj);
    index = vc_simplify(vc,index);
    Expr a_of_j = vc_readExpr(vc, cvcl_array, index);
    Expr ce = vc_getCounterExample(vc,a_of_j);    
  }
  vc_Destroy(vc);
  //vc_printCounterExample(vc);
  
  // FIXME: Actually test something
  //ASSERT_TRUE(false && "FIXME: Actually test something");
}
Esempio n. 4
0
void test9 (void)
{
  VC vc = vc_createValidityChecker (((void *) 0));
  Type bv32 = vc_bvType (vc, 32);
  Expr zero = vc_bvConstExprFromInt (vc, 32, 0);
  Expr one = vc_bvConstExprFromInt (vc, 32, 1);
  Expr a = vc_varExpr (vc, "a", bv32);
  Expr three = vc_bvConstExprFromInt (vc, 32, 3);
  Expr three64 = vc_bvSignExtend (vc, three, 64);
  Expr a64 = vc_bvSignExtend (vc, a, 64);
  Expr prod64 = vc_bvMultExpr (vc, 64, a64, three64);
  Expr min = vc_bvConstExprFromInt (vc, 32, (-2147483647 - 1));
  Expr max = vc_bvConstExprFromInt (vc, 32, 2147483647);
  Expr prod64_sge_min = vc_bvSGeExpr (vc, prod64, min);
  Expr prod64_sle_max = vc_bvSLeExpr (vc, prod64, max);
  Expr prod64_sge_min_and_sle_max =
    vc_andExpr (vc, prod64_sge_min, prod64_sle_max);
  vc_assertFormula (vc, prod64_sge_min_and_sle_max);
  Expr D3 = vc_varExpr (vc, "D3", bv32);
  Expr prod = vc_bvMultExpr (vc, 32, a, three);
  Expr D3_eq_prod = vc_eqExpr (vc, D3, prod);
  vc_assertFormula (vc, D3_eq_prod);
  Expr D4 = vc_varExpr (vc, "D4", bv32);
  Expr D3_sle_a_cond = vc_bvSLeExpr (vc, D3, a);
  Expr D3_sle_a_expr = vc_iteExpr (vc, D3_sle_a_cond, one, zero);
  Expr D4_eq_D3_sle_a_expr = vc_eqExpr (vc, D4, D3_sle_a_expr);
  vc_assertFormula (vc, D4_eq_D3_sle_a_expr);
  Expr D6 = vc_varExpr (vc, "D6", bv32);
  Expr D3_slt_a_cond = vc_bvSLtExpr (vc, D3, a);
  Expr D3_slt_a_expr = vc_iteExpr (vc, D3_slt_a_cond, one, zero);
  Expr D6_eq_D3_slt_a_expr = vc_eqExpr (vc, D6, D3_slt_a_expr);
  vc_assertFormula (vc, D6_eq_D3_slt_a_expr);
  Expr zero_lt_a = vc_bvSLtExpr (vc, zero, a);
  vc_assertFormula (vc, zero_lt_a);
  Expr D4_eq_one = vc_eqExpr (vc, D4, one);
  Expr not_D4_eq_one = vc_notExpr (vc, D4_eq_one);
  vc_query (vc, not_D4_eq_one);
  Expr D6_eq_one = vc_eqExpr (vc, D6, one);
  Expr not_D6_eq_one = vc_notExpr (vc, D6_eq_one);
  vc_query (vc, not_D6_eq_one);
  vc_destroyValidityChecker(vc);
}
Esempio n. 5
0
void test8 (void)
{
  Flags flags = vc_createFlags();
/*   vc_setStrSeqFlag(flags, "trace", "pushpop", 1); */
/*   vc_setStrSeqFlag(flags, "trace", "assertLit", 1); */
/*   vc_setStrSeqFlag(flags, "trace", "assertFactCore", 1); */
/*   vc_setStrSeqFlag(flags, "trace", "assertFormula", 1); */

  VC vc = vc_createValidityChecker (flags);
  Type bv32 = vc_bvType (vc, 32);
  Expr zero = vc_bvConstExprFromInt (vc, 32, 0);
  Expr one = vc_bvConstExprFromInt (vc, 32, 1);
  Expr a = vc_varExpr (vc, "a", bv32);
  Expr three = vc_bvConstExprFromInt (vc, 32, 3);
  Expr prod = vc_bvMultExpr (vc, 32, a, three);
  {
    Expr a64 = vc_bvSignExtend (vc, a, 64);
    Expr three64 = vc_bvSignExtend (vc, three, 64);
    Expr prod64 = vc_bvMultExpr (vc, 64, a64, three64);
    Expr max = vc_bvConstExprFromInt (vc, 32, 2147483647);
    Expr min = vc_bvConstExprFromInt (vc, 32, (-2147483647 - 1));
    Expr prod64_sge_min = vc_bvSGeExpr (vc, prod64, min);
    Expr prod64_sle_max = vc_bvSLeExpr (vc, prod64, max);
    Expr prod64_sge_min_and_sle_max =
      vc_andExpr (vc, prod64_sge_min, prod64_sle_max);
    vc_assertFormula (vc, prod64_sge_min_and_sle_max);
  }
  Expr D4 = vc_varExpr (vc, "D4", bv32);
  {
    Expr cond = vc_bvSLtExpr (vc, a, prod);
    Expr test = vc_iteExpr (vc, cond, one, zero);
    Expr D4_eq_test = vc_eqExpr (vc, D4, test);
    vc_assertFormula (vc, D4_eq_test);
  }
  Expr D6 = vc_varExpr (vc, "D6", bv32);
  {
    Expr cond = vc_bvSLeExpr (vc, a, prod);
    Expr test = vc_iteExpr (vc, cond, one, zero);
    Expr D6_eq_test = vc_eqExpr (vc, D6, test);
    vc_assertFormula (vc, D6_eq_test);
  }
  vc_push (vc);
  vc_pop (vc);
  vc_push (vc);
  {
    Expr cond = vc_bvSLtExpr (vc, a, zero);
    Expr test = vc_iteExpr (vc, cond, one, zero);
    Expr test_eq_one = vc_eqExpr (vc, test, one);
    vc_assertFormula (vc, test_eq_one);
    vc_push (vc);
    {
      Expr D4_eq_one = vc_eqExpr (vc, D4, one);
      vc_query (vc, D4_eq_one);
    }
    vc_pop (vc);
    vc_push (vc);
    vc_pop (vc);
    vc_push (vc);
    vc_pop (vc);
  }
  vc_pop (vc);
  {
    Expr cond = vc_eqExpr (vc, a, zero);
    Expr test = vc_iteExpr (vc, cond, one, zero);
    Expr test_eq_one = vc_eqExpr (vc, test, one);
    vc_assertFormula (vc, test_eq_one);
    vc_push (vc);
    vc_pop (vc);
    {
      Expr zero_eq_one = vc_eqExpr (vc, zero, one);
      vc_query (vc, zero_eq_one);
    }
  }
  vc_destroyValidityChecker(vc);
}
Esempio n. 6
0
void test4(int regressLevel)
{
  VC vc = vc_createValidityChecker(NULL);

  // Check x >= 10 /\ x >= 40 /\ y <= 0 -->
  //       x >= 1 /\ y < 10

  Type r = vc_realType(vc);
  Expr x = vc_varExpr(vc, "x", r);
  Expr y = vc_varExpr(vc, "y", r);

  Expr ten = vc_ratExpr(vc, 10, 1);
  Expr ge = vc_geExpr(vc, x, ten);

  Expr forty = vc_ratExpr(vc, 40, 1);
  Expr ge2 = vc_geExpr(vc, x, forty);

  Expr zero = vc_ratExpr(vc, 0, 1);
  Expr ge3 = vc_leExpr(vc, y, zero);

  Expr children[3];
  Expr hyp, one, conc, query;
  int i;

  children[0] = ge;
  children[1] = ge2;
  children[2] = ge3;

  hyp = vc_andExprN(vc, children, 3);

  vc_deleteType(r);
  vc_deleteExpr(ge);
  vc_deleteExpr(forty);
  vc_deleteExpr(ge2);
  vc_deleteExpr(zero);
  vc_deleteExpr(ge3);

  one = vc_ratExpr(vc, 1, 1);
  ge = vc_geExpr(vc, x, one);

  ge2 = vc_ltExpr(vc, y, ten);

  conc = vc_andExpr(vc, ge, ge2);
  query = vc_impliesExpr(vc, hyp, conc);

  vc_deleteExpr(x);
  vc_deleteExpr(y);
  vc_deleteExpr(ten);
  vc_deleteExpr(hyp);
  vc_deleteExpr(one);
  vc_deleteExpr(ge);
  vc_deleteExpr(ge2);
  vc_deleteExpr(conc);

  for (i = 0; i < 100*regressLevel; i++)
    vc_query(vc, query);

  vc_deleteExpr(query);

  vc_destroyValidityChecker(vc);
}
Esempio n. 7
0
value caml_vc_andExpr(value vc, value e1, value e2)
{
  CAMLparam3(vc,e1,e2);
  CAMLreturn(alloc_Expr(vc_andExpr(VC_val(vc),Expr_val(e1),Expr_val(e2))));
}