Skip to content

Commit 222d7e8

Browse files
committed
Change unit test for single pointer operand subtraction
1 parent cba0035 commit 222d7e8

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

unit/solvers/smt2_incremental/convert_expr_to_smt.cpp

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -557,20 +557,34 @@ TEST_CASE(
557557
smt_term_four_32bit));
558558
}
559559

560-
SECTION(
561-
"Ensure that conversion of a minus node with only one operand"
562-
"being a pointer fails")
560+
SECTION("Subtraction of an integer value from a pointer")
563561
{
564562
// (*int32_t)a - 2
565-
const cbmc_invariants_should_throwt invariants_throw;
566-
// We don't support that - look at the test above.
563+
564+
// NOTE: This may look similar to the above, but the above test
565+
// is a desugared version of this construct - with the difference
566+
// being that there exist cases where the construct is not desugared,
567+
// so we can still come across this expression as an input to
568+
// convert_expr_to_smt.
569+
const auto two_bvint = from_integer(2, signedbv_typet{pointer_width});
567570
const auto pointer_arith_expr = minus_exprt{pointer_a, two_bvint};
568-
REQUIRE_THROWS_MATCHES(
569-
test.convert(pointer_arith_expr),
570-
invariant_failedt,
571-
invariant_failure_containing(
572-
"convert_expr_to_smt::minus_exprt doesn't handle expressions where"
573-
"only one operand is a pointer - this is because these expressions"));
571+
572+
const symbol_tablet symbol_table;
573+
const namespacet ns{symbol_table};
574+
track_expression_objects(pointer_arith_expr, ns, test.object_map);
575+
associate_pointer_sizes(
576+
pointer_arith_expr,
577+
ns,
578+
test.pointer_sizes,
579+
test.object_map,
580+
test.object_size_function.make_application);
581+
INFO("Input expr: " + pointer_arith_expr.pretty(2, 0));
582+
const auto constructed_term = test.convert(pointer_arith_expr);
583+
const auto expected_term = smt_bit_vector_theoryt::subtract(
584+
smt_term_a,
585+
smt_bit_vector_theoryt::multiply(
586+
smt_term_two_32bit, smt_term_four_32bit));
587+
REQUIRE(constructed_term == expected_term);
574588
}
575589

576590
SECTION("Subtraction of two pointer arguments")

0 commit comments

Comments
 (0)