File tree 3 files changed +54
-0
lines changed
unit/solvers/smt2_incremental 3 files changed +54
-0
lines changed Original file line number Diff line number Diff line change @@ -557,6 +557,13 @@ static smt_termt convert_expr_to_smt(const shift_exprt &shift)
557
557
convert_expr_to_smt (left_shift->op0 ()),
558
558
convert_expr_to_smt (left_shift->op1 ()));
559
559
}
560
+ else if (
561
+ const auto right_logical_shift = expr_try_dynamic_cast<lshr_exprt>(shift))
562
+ {
563
+ return smt_bit_vector_theoryt::logical_shift_right (
564
+ convert_expr_to_smt (right_logical_shift->op0 ()),
565
+ convert_expr_to_smt (right_logical_shift->op1 ()));
566
+ }
560
567
561
568
// TODO: split into functions for separate types of shift including rotate.
562
569
UNIMPLEMENTED_FEATURE (
Original file line number Diff line number Diff line change @@ -364,6 +364,12 @@ class lshr_exprt : public shift_exprt
364
364
}
365
365
};
366
366
367
+ template <>
368
+ inline bool can_cast_expr<lshr_exprt>(const exprt &base)
369
+ {
370
+ return base.id () == ID_lshr;
371
+ }
372
+
367
373
// / \brief Extracts a single bit of a bit-vector operand
368
374
class extractbit_exprt : public binary_predicate_exprt
369
375
{
Original file line number Diff line number Diff line change @@ -714,3 +714,44 @@ SCENARIO(
714
714
}
715
715
}
716
716
}
717
+
718
+ SCENARIO (
719
+ " Logical Right-shift expressions are converted to SMT terms" ,
720
+ " [core][smt2_incremental]" )
721
+ {
722
+ GIVEN (" An integer bitvector" )
723
+ {
724
+ const auto one_bvint = from_integer ({1 }, signedbv_typet{8 });
725
+
726
+ WHEN (" We construct a lshr_exprt and convert it to an SMT term" )
727
+ {
728
+ const auto shift_expr = lshr_exprt{one_bvint, one_bvint};
729
+ const auto constructed_term = convert_expr_to_smt (shift_expr);
730
+
731
+ THEN (" We should get an logical shift left SMT term" )
732
+ {
733
+ const smt_termt smt_term_one = smt_bit_vector_constant_termt{1 , 8 };
734
+ const auto expected_term = smt_bit_vector_theoryt::logical_shift_right (
735
+ /* Value to be shifted */
736
+ smt_term_one,
737
+ /* Places */
738
+ smt_term_one);
739
+ REQUIRE (constructed_term == expected_term);
740
+ }
741
+ }
742
+
743
+ WHEN (
744
+ " We construct a malformed lshr_exprt and attempt to convert it to an SMT"
745
+ " term" )
746
+ {
747
+ const cbmc_invariants_should_throwt invariants_throw;
748
+ THEN (
749
+ " convert_expr_to_smt should throw an exception because of validation "
750
+ " failure" )
751
+ {
752
+ REQUIRE_THROWS (
753
+ convert_expr_to_smt (lshr_exprt{one_bvint, false_exprt{}}));
754
+ }
755
+ }
756
+ }
757
+ }
You can’t perform that action at this time.
0 commit comments