Skip to content

Commit 731ff1f

Browse files
committed
Add a test for making sure we hit the invariant in case we subtract a pointer from a constant
1 parent 222d7e8 commit 731ff1f

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

unit/solvers/smt2_incremental/convert_expr_to_smt.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,21 @@ TEST_CASE(
587587
REQUIRE(constructed_term == expected_term);
588588
}
589589

590+
SECTION("Subtraction of pointer from integer")
591+
{
592+
// 2 - (*int32_t)a -- Semantically void expression, need to make sure
593+
// we throw in this case.
594+
const cbmc_invariants_should_throwt invariants_throw;
595+
596+
const auto pointer_arith_expr = minus_exprt{two_bvint, pointer_a};
597+
598+
REQUIRE_THROWS_MATCHES(
599+
test.convert(pointer_arith_expr),
600+
invariant_failedt,
601+
invariant_failure_containing("minus expressions of pointer and integer "
602+
"expect lhs to be the pointer"));
603+
}
604+
590605
SECTION("Subtraction of two pointer arguments")
591606
{
592607
// (int32_t *)a - (int32_t *)b

0 commit comments

Comments
 (0)