@@ -644,11 +644,44 @@ static smt_termt convert_expr_to_smt(
644
644
can_cast_type<integer_bitvector_typet>(minus.lhs ().type ()) &&
645
645
can_cast_type<integer_bitvector_typet>(minus.rhs ().type ());
646
646
647
+ const bool lhs_is_pointer = can_cast_type<pointer_typet>(minus.lhs ().type ());
648
+ const bool rhs_is_pointer = can_cast_type<pointer_typet>(minus.rhs ().type ());
649
+
650
+ const bool both_operands_pointers = lhs_is_pointer && rhs_is_pointer;
651
+
652
+ // We don't really handle this - we just compute this to fall
653
+ // into an if-else branch that gives proper error handling information.
654
+ const bool one_operand_pointer = lhs_is_pointer || rhs_is_pointer;
655
+
647
656
if (both_operands_bitvector)
648
657
{
649
658
return smt_bit_vector_theoryt::subtract (
650
659
converted.at (minus.lhs ()), converted.at (minus.rhs ()));
651
660
}
661
+ else if (both_operands_pointers)
662
+ {
663
+ const auto lhs_base_type = to_pointer_type (minus.lhs ().type ()).base_type ();
664
+ const auto rhs_base_type = to_pointer_type (minus.rhs ().type ()).base_type ();
665
+ INVARIANT (
666
+ lhs_base_type == rhs_base_type,
667
+ " only pointers of the same object type can be subtracted." );
668
+ return smt_bit_vector_theoryt::unsigned_divide (
669
+ smt_bit_vector_theoryt::subtract (
670
+ converted.at (minus.lhs ()), converted.at (minus.rhs ())),
671
+ pointer_sizes.at (lhs_base_type));
672
+ }
673
+ else if (one_operand_pointer)
674
+ {
675
+ UNIMPLEMENTED_FEATURE (
676
+ " convert_expr_to_smt::minus_exprt doesn't handle expressions where"
677
+ " only one operand is a pointer - this is because these expressions"
678
+ " are normally handled by convert_expr_to_smt::plus_exprt due to"
679
+ " transformations of the expressions by previous passes bringing"
680
+ " them into a form more suitably handled by that version of the function."
681
+ " If you are here, this is a mistake or something went wrong before."
682
+ " The expression that caused the problem is: " +
683
+ minus.pretty ());
684
+ }
652
685
else
653
686
{
654
687
UNIMPLEMENTED_FEATURE (
@@ -1452,7 +1485,7 @@ static smt_termt dispatch_expr_to_smt_conversion(
1452
1485
}
1453
1486
if (const auto minus = expr_try_dynamic_cast<minus_exprt>(expr))
1454
1487
{
1455
- return convert_expr_to_smt (*minus, converted);
1488
+ return convert_expr_to_smt (*minus, converted, pointer_sizes );
1456
1489
}
1457
1490
if (const auto divide = expr_try_dynamic_cast<div_exprt>(expr))
1458
1491
{
0 commit comments