@@ -714,3 +714,103 @@ SCENARIO(
714714 }
715715 }
716716}
717+
718+ SCENARIO (
719+ " Logical Right-shift expressions are converted to SMT terms" ,
720+ " [core][smt2_incremental]" )
721+ {
722+ GIVEN (" Two integer bitvectors, one for the value and one for the places" )
723+ {
724+ const auto to_be_shifted = from_integer (1 , signedbv_typet{8 });
725+ const auto places = from_integer (2 , signedbv_typet{8 });
726+
727+ WHEN (" We construct a lshr_exprt and convert it to an SMT term" )
728+ {
729+ const auto shift_expr = lshr_exprt{to_be_shifted, places};
730+ const auto constructed_term = convert_expr_to_smt (shift_expr);
731+
732+ THEN (" We should get an logical shift right SMT term" )
733+ {
734+ const smt_termt smt_term_value = smt_bit_vector_constant_termt{1 , 8 };
735+ const smt_termt smt_term_places = smt_bit_vector_constant_termt{2 , 8 };
736+ const auto expected_term = smt_bit_vector_theoryt::logical_shift_right (
737+ smt_term_value, smt_term_places);
738+ REQUIRE (constructed_term == expected_term);
739+ }
740+ }
741+
742+ WHEN (
743+ " We construct a malformed lshr_exprt and attempt to convert it to an SMT"
744+ " term" )
745+ {
746+ const cbmc_invariants_should_throwt invariants_throw;
747+ THEN (
748+ " convert_expr_to_smt should throw an exception because of validation "
749+ " failure" )
750+ {
751+ REQUIRE_THROWS (
752+ convert_expr_to_smt (lshr_exprt{to_be_shifted, false_exprt{}}));
753+ }
754+ }
755+ }
756+ }
757+
758+ SCENARIO (
759+ " Arithmetic Right-shift expressions are converted to SMT terms" ,
760+ " [core][smt2_incremental]" )
761+ {
762+ GIVEN (" Two integer bitvectors, one for the value and one for the places" )
763+ {
764+ const auto to_be_shifted = from_integer (1 , signedbv_typet{8 });
765+ const auto places = from_integer (2 , signedbv_typet{8 });
766+
767+ WHEN (" We construct a ashr_exprt and convert it to an SMT term" )
768+ {
769+ const auto shift_expr = ashr_exprt{to_be_shifted, places};
770+ const auto constructed_term = convert_expr_to_smt (shift_expr);
771+
772+ THEN (" We should get an arithmetic shift-right SMT term" )
773+ {
774+ const smt_termt smt_term_value = smt_bit_vector_constant_termt{1 , 8 };
775+ const smt_termt smt_term_places = smt_bit_vector_constant_termt{2 , 8 };
776+ const auto expected_term =
777+ smt_bit_vector_theoryt::arithmetic_shift_right (
778+ smt_term_value, smt_term_places);
779+ REQUIRE (constructed_term == expected_term);
780+ }
781+ }
782+
783+ WHEN (" We construct an ashr_exprt and with a shift of 0 places" )
784+ {
785+ const auto zero_places = from_integer (0 , signedbv_typet{8 });
786+ const auto shift_expr = ashr_exprt{to_be_shifted, zero_places};
787+ const auto constructed_term = convert_expr_to_smt (shift_expr);
788+
789+ THEN (
790+ " When we convert it, we should be getting an arithmetic shift-right "
791+ " term" )
792+ {
793+ const smt_termt smt_term_value = smt_bit_vector_constant_termt{1 , 8 };
794+ const smt_termt smt_term_places = smt_bit_vector_constant_termt{0 , 8 };
795+ const auto expected_term =
796+ smt_bit_vector_theoryt::arithmetic_shift_right (
797+ smt_term_value, smt_term_places);
798+ REQUIRE (constructed_term == expected_term);
799+ }
800+ }
801+
802+ WHEN (
803+ " We construct a malformed ashr_exprt and attempt to convert it to an SMT "
804+ " term" )
805+ {
806+ const cbmc_invariants_should_throwt invariants_throw;
807+ THEN (
808+ " convert_expr_to_smt should throw an exception because of validation "
809+ " failure" )
810+ {
811+ REQUIRE_THROWS (
812+ convert_expr_to_smt (ashr_exprt{to_be_shifted, false_exprt{}}));
813+ }
814+ }
815+ }
816+ }
0 commit comments