Skip to content

Commit 81cf965

Browse files
committed
Add a test for making sure we hit the invariant in case we subtract a pointer from a constant
1 parent 277ba6d commit 81cf965

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

unit/solvers/smt2_incremental/convert_expr_to_smt.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,22 @@ TEST_CASE(
586586
smt_term_four_32bit));
587587
}
588588

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

0 commit comments

Comments
 (0)