Closed rasoolmaghareh closed 11 months ago
This program fails while converting the Expr::Xor
expr at txExpr2z3Expr()
.
In this program, every variable is of integer type and we are applying boolean operations on them.
int polynomial(int p1, int p2) {
int x = 0;
if (((2 * (p1 ^ 3)) - (p1 ^ 2) - (7 * p1) + 2) == 0) // p1=2
x = x + 2;
if (p2 > 5)
x = x * 2;
return x;
}
Here ^
is Xor operator.
During the Tx to Z3 expr conversion for Xor expressions, z3 checks whether the variables are of boolean type or not. It is failing to satisfy this condition.
As the program name suggests (polynomial.c), ^ used here is actually meant for the power operation.
Can we add support for xor to Z3 solver class?
At present we are dealing with the xor operations in the following manner:
case Expr::Xor: {
z3::expr t1 = c.bool_val(false);
bool r1 = txExpr2z3Expr(t1, c, txe->getKid(0), emap);
if (r1) {
z3::expr t2 = c.bool_val(false);
bool r2 = txExpr2z3Expr(t2, c, txe->getKid(1), emap);
if (r2) {
z3e = not(not(t2) && not(t1));
return true;
}
}
return false;
}
We are utilizing the not operator from Z3++.h
to formulate the Xor operator.
The code for not in Z3++.h
is as follows:
inline expr operator!(expr const & a) { //std::cout<<"not !!";
assert(a.is_bool()); _Z3_MK_UN_(a, Z3_mk_not); }
This function checks whether the operand is Boolean or not. Since our operands are not Boolean type, we are facing the crash.
Let's try to add a warning message for this case to avoid a crash and not do the simplification.
Avoided Z3simplification whenever a non-boolean operand is passed to XOR or NOT operators. (Commit 4b0c2b8dfc11794dceef381b8498af892af91015)
WP output:
************Basic Block Coverage Report Starts****************
KLEE: done: Total number of single time Visited Basic Blocks: 5
KLEE: done: Total number of Basic Blocks: 6
************Basic Block Coverage Report Ends****************
************ICMP/Atomic Condition Coverage Report Starts****************
KLEE: done: Total number of Covered ICMP/Atomic Condition: 2
KLEE: done: Total number of All ICMP/Atomic Condition: 2
************ICMP/Atomic Condition Coverage Report Ends****************
KLEE: Memory cap NOT exceeded!
KLEE: done: Total reduced symbolic execution tree nodes = 3
KLEE: done: Total number of visited basic blocks = 5
KLEE: done: Subsumption statistics
KLEE: done: Time for actual solver calls in subsumption check (ms) = 0
KLEE: done: Number of solver calls for subsumption check (failed) = 0 (0)
KLEE: done: Concrete store expression build time (ms) = 0
KLEE: done: Symbolic store expression build time (ms) = 0
KLEE: done: Solver access time (ms) = 0
KLEE: done: Average table entries per subsumption checkpoint = 1.00
KLEE: done: Number of subsumption checks = 3
KLEE: done: Average solver calls per subsumption check = 0.00
KLEE: done: TxTree method execution times (ms):
KLEE: done: setCurrentINode = 0.199
KLEE: done: remove = 1.731
KLEE: done: subsumptionCheck = 0.138
KLEE: done: markPathCondition = 0.041
KLEE: done: split = 0.02
KLEE: done: executeOnNode = 0.107
KLEE: done: executeMemoryOperation = 0.546
KLEE: done: TxTreeNode method execution times (ms):
KLEE: done: getInterpolant = 0.002
KLEE: done: get WP Interpolant = 0.956
KLEE: done: addConstraintTime = 0.098
KLEE: done: splitTime = 0.016
KLEE: done: execute = 0.097
KLEE: done: bindCallArguments = 0.008
KLEE: done: bindReturnValue = 0.005
KLEE: done: getStoredExpressions = 0
KLEE: done: getStoredCoreExpressions = 0.01
KLEE: done: total instructions = 42
KLEE: done: completed paths = 2, among which
KLEE: done: early-terminating paths (instruction time limit, solver timeout, max-depth reached) = 0
KLEE: done: average branching depth of completed paths = 1
KLEE: done: average branching depth of subsumed paths = 0
KLEE: done: average instructions of completed paths = 35.5
KLEE: done: average instructions of subsumed paths = 0
KLEE: done: subsumed paths = 0
KLEE: done: error paths = 0
KLEE: done: program exit paths = 2
KLEE: done: generated tests = 0, among which
KLEE: done: early-terminating tests (instruction time limit, solver timeout, max-depth reached) = 0
KLEE: done: error tests = 0
KLEE: done: program exit tests = 0
KLEE: done: NOTE:
KLEE: done: Subsumed paths / tests counts are nondeterministic for
KLEE: done: programs with dynamically-allocated memory such as those
KLEE: done: using malloc, since KLEE may reuse the address of the
KLEE: done: same malloc calls in different paths. This nondeterminism
KLEE: done: does not cause loss of error reports.
--------------------------------------------------------------------------------------
| Path | Instrs| Time(s)| ICov(%)| BCov(%)| ICount| TSolver(%)|
--------------------------------------------------------------------------------------
|polynomial-3/klee-out-0| 42| 0.14| 12.79| 4.29| 305| 93.77|
--------------------------------------------------------------------------------------
Issue Fixed.
This is the output that I am seeing: