File tree 2 files changed +48
-3
lines changed
src/solvers/smt2_incremental
unit/solvers/smt2_incremental 2 files changed +48
-3
lines changed Original file line number Diff line number Diff line change @@ -217,9 +217,19 @@ static smt_termt convert_expr_to_smt(const bitxor_exprt &bitwise_xor)
217
217
218
218
static smt_termt convert_expr_to_smt (const bitnot_exprt &bitwise_not)
219
219
{
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
+ }
223
233
}
224
234
225
235
static smt_termt convert_expr_to_smt (const unary_minus_exprt &unary_minus)
Original file line number Diff line number Diff line change @@ -637,3 +637,38 @@ SCENARIO(
637
637
}
638
638
}
639
639
}
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
+ }
You can’t perform that action at this time.
0 commit comments