Skip to content

Commit 51674f8

Browse files
committed
SMT2 backend: convert pointer minus scalar
This adds the missing conversion for "pointer - scalar" to the SMT2 backend. It's not used by CBMC, which rewrites these to p+(-s) in the simplifier.
1 parent 5c1c334 commit 51674f8

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/solvers/smt2/smt2_conv.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3587,7 +3587,19 @@ void smt2_convt::convert_minus(const minus_exprt &expr)
35873587
}
35883588
else if(expr.type().id()==ID_pointer)
35893589
{
3590-
SMT2_TODO("pointer subtraction");
3590+
if(
3591+
expr.op0().type().id() == ID_pointer &&
3592+
(expr.op1().type().id() == ID_unsignedbv ||
3593+
expr.op1().type().id() == ID_signedbv))
3594+
{
3595+
// rewrite p-o to p+(-o)
3596+
return convert_plus(
3597+
plus_exprt(expr.op0(), unary_minus_exprt(expr.op1())));
3598+
}
3599+
else
3600+
UNEXPECTEDCASE(
3601+
"unsupported operand types for -: " + expr.op0().type().id_string() +
3602+
" and " + expr.op1().type().id_string());
35913603
}
35923604
else if(expr.type().id()==ID_vector)
35933605
{

0 commit comments

Comments
 (0)