Skip to content

Commit 582fe78

Browse files
committed
Add unit tests for relational operators on pointers in new SMT backend
1 parent 7094f98 commit 582fe78

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

unit/solvers/smt2_incremental/convert_expr_to_smt.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,51 @@ TEST_CASE(
327327
}
328328
}
329329

330+
TEST_CASE(
331+
"expr to smt conversion for relational operators as applied to pointers",
332+
"[core][smt2_incremental]")
333+
{
334+
auto test = expr_to_smt_conversion_test_environmentt::make(test_archt::i386);
335+
// Pointer variables, used for comparisons
336+
const std::size_t pointer_width = 32;
337+
const auto pointer_type = pointer_typet(signedbv_typet{32}, pointer_width);
338+
const symbol_exprt pointer_a("a", pointer_type);
339+
const symbol_exprt pointer_b("b", pointer_type);
340+
// SMT terms needed for pointer comparisons
341+
const smt_termt smt_term_a =
342+
smt_identifier_termt{"a", smt_bit_vector_sortt{pointer_width}};
343+
const smt_termt smt_term_b =
344+
smt_identifier_termt{"b", smt_bit_vector_sortt{pointer_width}};
345+
346+
SECTION("Greater than on pointers")
347+
{
348+
CHECK(
349+
test.convert(greater_than_exprt{pointer_a, pointer_b}) ==
350+
smt_bit_vector_theoryt::unsigned_greater_than(smt_term_a, smt_term_b));
351+
}
352+
353+
SECTION("Greater than or equal on pointer operands")
354+
{
355+
CHECK(
356+
test.convert(greater_than_or_equal_exprt{pointer_a, pointer_b}) ==
357+
smt_bit_vector_theoryt::unsigned_greater_than_or_equal(
358+
smt_term_a, smt_term_b));
359+
}
360+
SECTION("Less than on pointer operands")
361+
{
362+
CHECK(
363+
test.convert(less_than_exprt{pointer_a, pointer_b}) ==
364+
smt_bit_vector_theoryt::unsigned_less_than(smt_term_a, smt_term_b));
365+
}
366+
SECTION("Less than or equal on pointer operands")
367+
{
368+
CHECK(
369+
test.convert(less_than_or_equal_exprt{pointer_a, pointer_b}) ==
370+
smt_bit_vector_theoryt::unsigned_less_than_or_equal(
371+
smt_term_a, smt_term_b));
372+
}
373+
}
374+
330375
TEST_CASE(
331376
"expr to smt conversion for arithmetic operators",
332377
"[core][smt2_incremental]")

0 commit comments

Comments
 (0)