@@ -641,17 +641,39 @@ static smt_termt convert_expr_to_smt(
641641
642642static smt_termt convert_expr_to_smt (
643643 const minus_exprt &minus,
644- const sub_expression_mapt &converted)
644+ const sub_expression_mapt &converted,
645+ const pointer_size_mapt &pointer_sizes)
645646{
646647 const bool both_operands_bitvector =
647648 can_cast_type<integer_bitvector_typet>(minus.lhs ().type ()) &&
648649 can_cast_type<integer_bitvector_typet>(minus.rhs ().type ());
649650
650- if (both_operands_bitvector)
651+ const bool lhs_is_pointer = can_cast_type<pointer_typet>(minus.lhs ().type ());
652+ const bool rhs_is_pointer = can_cast_type<pointer_typet>(minus.rhs ().type ());
653+
654+ const bool both_operands_pointers = lhs_is_pointer && rhs_is_pointer;
655+
656+ // We don't really handle this - we just compute this to fall
657+ // into an if-else branch that gives proper error handling information.
658+ const bool one_operand_pointer = lhs_is_pointer || rhs_is_pointer;
659+
660+ if (both_operands_bitvector || both_operands_pointers)
651661 {
652662 return smt_bit_vector_theoryt::subtract (
653663 converted.at (minus.lhs ()), converted.at (minus.rhs ()));
654664 }
665+ else if (one_operand_pointer)
666+ {
667+ UNIMPLEMENTED_FEATURE (
668+ " convert_expr_to_smt::minus_exprt doesn't handle expressions where"
669+ " only one operand is a pointer - this is because these expressions"
670+ " are normally handled by convert_expr_to_smt::plus_exprt due to"
671+ " transformations of the expressions by previous passes bringing"
672+ " them into a form more suitably handled by that version of the function."
673+ " If you are here, this is a mistake or something went wrong before."
674+ " The expression that caused the problem is: " +
675+ minus.pretty ());
676+ }
655677 else
656678 {
657679 UNIMPLEMENTED_FEATURE (
@@ -1455,7 +1477,7 @@ static smt_termt dispatch_expr_to_smt_conversion(
14551477 }
14561478 if (const auto minus = expr_try_dynamic_cast<minus_exprt>(expr))
14571479 {
1458- return convert_expr_to_smt (*minus, converted);
1480+ return convert_expr_to_smt (*minus, converted, pointer_sizes );
14591481 }
14601482 if (const auto divide = expr_try_dynamic_cast<div_exprt>(expr))
14611483 {
0 commit comments