TEST(reported_issue_120, one) { VC vc = vc_createValidityChecker(); // Numbers will be non-negatives integers bounded at 2^32 Type bv32 = vc_bvType(vc, 32); // Determine whether the following equations are satisfiable: // v + 4 = n // 4 = n // Construct variable n Expr n = vc_varExpr(vc, "n", bv32); // Construct v + 4 Expr v = vc_varExpr(vc, "v", bv32); Expr ct_4 = vc_bvConstExprFromInt(vc, 32, 4); Expr add_v_4 = vc_bvPlusExpr(vc, 32, v, ct_4); // Because numbers are represented as bit vectors, // addition can roll over. So construct a constraint // expresses that v+4 does not overflow the bounds: // v + 4 >= v // Expr ge = vc_bvGeExpr(vc, add_v_4, v); // Push a new context printf("Push\n"); vc_push(vc); // Assert v + 4 = n printf("Assert v + 4 = n\n"); Expr f_add = vc_eqExpr(vc, add_v_4, n); vc_assertFormula(vc, f_add); vc_printExpr(vc, f_add); printf("\n------\n"); // Assert the bounds constraint printf("Assert v + 4 >= v\n"); vc_assertFormula(vc, ge); vc_printExpr(vc, ge); printf("\n------\n"); // Assert 4 = n printf("Assert 4 = n\n"); Expr f_numeq = vc_eqExpr(vc, ct_4, n); vc_assertFormula(vc, f_numeq); vc_printExpr(vc, f_numeq); printf("\n------\n"); // Check for satisfiability printf("Check\n"); vc_printAsserts(vc); printf("\n------\n"); int query = vc_query(vc, vc_falseExpr(vc)); ASSERT_EQ(query, 0); // Pop context printf("Pop\n"); vc_pop(vc); printf("query = %d\n", query); }
value caml_vc_bvGeExpr(value vc, value e1, value e2) { CAMLparam3(vc,e1,e2); CAMLreturn(alloc_Expr(vc_bvGeExpr(VC_val(vc),Expr_val(e1),Expr_val(e2)))); }