Skip to content

Commit d5526a3

Browse files
committed
Add implementation and tests for conversion of bitnot_exprt to bvnot SMT terms.
1 parent 6b99d17 commit d5526a3

File tree

2 files changed

+48
-3
lines changed

2 files changed

+48
-3
lines changed

src/solvers/smt2_incremental/convert_expr_to_smt.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,19 @@ static smt_termt convert_expr_to_smt(const bitxor_exprt &bitwise_xor)
217217

218218
static smt_termt convert_expr_to_smt(const bitnot_exprt &bitwise_not)
219219
{
220-
UNIMPLEMENTED_FEATURE(
221-
"Generation of SMT formula for bitwise not expression: " +
222-
bitwise_not.pretty());
220+
const bool operand_is_bitvector =
221+
can_cast_type<integer_bitvector_typet>(bitwise_not.op().type());
222+
223+
if(operand_is_bitvector)
224+
{
225+
return smt_bit_vector_theoryt::make_not(
226+
convert_expr_to_smt(bitwise_not.op()));
227+
}
228+
else
229+
{
230+
UNIMPLEMENTED_FEATURE(
231+
"Generation of SMT formula for bitnot_exprt: " + bitwise_not.pretty());
232+
}
223233
}
224234

225235
static smt_termt convert_expr_to_smt(const unary_minus_exprt &unary_minus)

unit/solvers/smt2_incremental/convert_expr_to_smt.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,3 +637,38 @@ SCENARIO(
637637
}
638638
}
639639
}
640+
641+
SCENARIO(
642+
"Bitwise \"NOT\" expressions are converted to SMT terms (1's complement)",
643+
"[core][smt2_incremental]")
644+
{
645+
GIVEN("An integer bitvector")
646+
{
647+
const auto one_bvint = from_integer({1}, signedbv_typet{8});
648+
649+
WHEN("A bitnot_exprt is constructed and converted to an SMT term")
650+
{
651+
const auto constructed_term =
652+
convert_expr_to_smt(bitnot_exprt{one_bvint});
653+
THEN("it should be converted to bvnot smt term")
654+
{
655+
const smt_termt smt_term_one = smt_bit_vector_constant_termt{1, 8};
656+
const auto expected_term =
657+
smt_bit_vector_theoryt::make_not(smt_term_one);
658+
659+
REQUIRE(constructed_term == expected_term);
660+
}
661+
}
662+
663+
WHEN("A bitnot_exprt is constructed with a false expression and converted")
664+
{
665+
const cbmc_invariants_should_throwt invariants_throw;
666+
THEN(
667+
"convert_expr_to_smt should throw an exception and not allow "
668+
"construction")
669+
{
670+
REQUIRE_THROWS(convert_expr_to_smt(bitnot_exprt{false_exprt{}}));
671+
}
672+
}
673+
}
674+
}

0 commit comments

Comments
 (0)