Skip to content

Commit 0e33060

Browse files
committed
Add unit tests for conversion of pointer_offset_exprt to SMT
1 parent c5ed70a commit 0e33060

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

unit/solvers/smt2_incremental/convert_expr_to_smt.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,3 +1241,35 @@ TEST_CASE(
12411241
CHECK(converted == expected);
12421242
}
12431243
}
1244+
1245+
TEST_CASE("pointer_offset_exprt to SMT conversion", "[core][smt2_incremental]")
1246+
{
1247+
const symbol_exprt foo{"foo", pointer_typet(unsigned_int_type(), 64)};
1248+
1249+
SECTION("simple pointer_offset_exprt conversion")
1250+
{
1251+
const pointer_offset_exprt pointer_offset_exp =
1252+
*expr_try_dynamic_cast<pointer_offset_exprt>(pointer_offset(foo));
1253+
const auto converted = convert_expr_to_smt(pointer_offset_exp);
1254+
const auto expected =
1255+
smt_bit_vector_theoryt::zero_extend(8)(smt_bit_vector_theoryt::extract(
1256+
55, 0)(smt_identifier_termt("foo", smt_bit_vector_sortt(64))));
1257+
CHECK(converted == expected);
1258+
}
1259+
1260+
SECTION("Invariant checks")
1261+
{
1262+
const cbmc_invariants_should_throwt invariants_throw;
1263+
SECTION("pointer_offset_exprt's operand type should be a bitvector type")
1264+
{
1265+
pointer_offset_exprt pointer_offset_exp =
1266+
*expr_try_dynamic_cast<pointer_offset_exprt>(pointer_offset(foo));
1267+
pointer_offset_exp.type() = bool_typet{};
1268+
REQUIRE_THROWS_MATCHES(
1269+
convert_expr_to_smt(pointer_offset_exp),
1270+
invariant_failedt,
1271+
invariant_failure_containing(
1272+
"Pointer offset should have a bitvector-based type."));
1273+
}
1274+
}
1275+
}

0 commit comments

Comments
 (0)