File tree 3 files changed +56
-0
lines changed
unit/solvers/smt2_incremental 3 files changed +56
-0
lines changed Original file line number Diff line number Diff line change @@ -550,6 +550,14 @@ static smt_termt convert_expr_to_smt(const index_exprt &index)
550
550
551
551
static smt_termt convert_expr_to_smt (const shift_exprt &shift)
552
552
{
553
+ // TODO: Dispatch into different types of shifting
554
+ if (const auto left_shift = expr_try_dynamic_cast<shl_exprt>(shift))
555
+ {
556
+ return smt_bit_vector_theoryt::shift_left (
557
+ convert_expr_to_smt (left_shift->op0 ()),
558
+ convert_expr_to_smt (left_shift->op1 ()));
559
+ }
560
+
553
561
// TODO: split into functions for separate types of shift including rotate.
554
562
UNIMPLEMENTED_FEATURE (
555
563
" Generation of SMT formula for shift expression: " + shift.pretty ());
Original file line number Diff line number Diff line change @@ -305,6 +305,12 @@ class shl_exprt : public shift_exprt
305
305
}
306
306
};
307
307
308
+ template <>
309
+ inline bool can_cast_expr<shl_exprt>(const exprt &base)
310
+ {
311
+ return base.id () == ID_shl;
312
+ }
313
+
308
314
// / \brief Cast an exprt to a \ref shl_exprt
309
315
// /
310
316
// / \a expr must be known to be \ref shl_exprt.
Original file line number Diff line number Diff line change @@ -672,3 +672,45 @@ SCENARIO(
672
672
}
673
673
}
674
674
}
675
+
676
+ SCENARIO (
677
+ " Left-shift expressions are converted to SMT terms" ,
678
+ " [core][smt2_incremental]" )
679
+ {
680
+ GIVEN (" An integer bitvector and the number of places we're going to shift" )
681
+ {
682
+ // This is going to act as both the value to be shifted, and a value
683
+ // signifying the places to the left we're shifting.
684
+ const auto one_bvint = from_integer ({1 }, signedbv_typet{8 });
685
+
686
+ WHEN (" We construct a shl_exprt and convert it to an SMT term" )
687
+ {
688
+ const auto shift_expr = shl_exprt{one_bvint, one_bvint};
689
+ const auto constructed_term = convert_expr_to_smt (shift_expr);
690
+
691
+ THEN (" It should be equivalent to a bvshl term" )
692
+ {
693
+ const smt_termt smt_term_one = smt_bit_vector_constant_termt{1 , 8 };
694
+ const auto expected_term = smt_bit_vector_theoryt::shift_left (
695
+ /* term */
696
+ smt_term_one,
697
+ /* distance */
698
+ smt_term_one);
699
+ }
700
+ }
701
+
702
+ WHEN (
703
+ " We construct a malformed shl_exprt and attempt to convert it to an SMT "
704
+ " term" )
705
+ {
706
+ const cbmc_invariants_should_throwt invariants_throw;
707
+ THEN (
708
+ " convert_expr_to_smt should throw an exception because of validation "
709
+ " failure" )
710
+ {
711
+ REQUIRE_THROWS (
712
+ convert_expr_to_smt (shl_exprt{one_bvint, false_exprt{}}));
713
+ }
714
+ }
715
+ }
716
+ }
You can’t perform that action at this time.
0 commit comments