Skip to content

Commit 43cdaa3

Browse files
committed
Add support for conversion of addition with pointer operand to new SMT backend.
1 parent a41bbb9 commit 43cdaa3

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

src/solvers/smt2_incremental/convert_expr_to_smt.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,43 @@ static smt_termt convert_expr_to_smt(
598598
return convert_multiary_operator_to_terms(
599599
plus, converted, smt_bit_vector_theoryt::add);
600600
}
601+
else if(can_cast_type<pointer_typet>(plus.type()))
602+
{
603+
INVARIANT(
604+
plus.operands().size() == 2,
605+
"We are only handling a binary version of plus when it has a pointer "
606+
"operand");
607+
608+
exprt pointer;
609+
exprt scalar;
610+
for(auto &operand : plus.operands())
611+
{
612+
if(can_cast_type<pointer_typet>(operand.type()))
613+
{
614+
pointer = operand;
615+
}
616+
else
617+
{
618+
scalar = operand;
619+
}
620+
}
621+
622+
// We need to ensure that we follow this code path only if the expression
623+
// our assumptions about the structure of the addition expression hold.
624+
INVARIANT(
625+
!can_cast_type<pointer_typet>(scalar.type()),
626+
"An addition expression with both operands being pointers when they are "
627+
"not dereferenced is malformed");
628+
629+
const pointer_typet pointer_type =
630+
*type_try_dynamic_cast<pointer_typet>(pointer.type());
631+
const auto base_type = pointer_type.base_type();
632+
const auto pointer_size = pointer_sizes.at(base_type);
633+
634+
return smt_bit_vector_theoryt::add(
635+
converted.at(pointer),
636+
smt_bit_vector_theoryt::multiply(converted.at(scalar), pointer_size));
637+
}
601638
else
602639
{
603640
UNIMPLEMENTED_FEATURE(

0 commit comments

Comments
 (0)