@@ -819,6 +819,105 @@ SCENARIO(
819
819
}
820
820
}
821
821
822
+ TEST_CASE (
823
+ " expr to smt conversion for shifts of mismatched operands." ,
824
+ " [core][smt2_incremental]" )
825
+ {
826
+ using make_typet = std::function<typet (std::size_t )>;
827
+ const make_typet make_unsigned = constructor_oft<unsignedbv_typet>{};
828
+ const make_typet make_signed = constructor_oft<signedbv_typet>{};
829
+ using make_extensiont =
830
+ std::function<std::function<smt_termt (smt_termt)>(std::size_t )>;
831
+ const make_extensiont zero_extend = smt_bit_vector_theoryt::zero_extend;
832
+ const make_extensiont sign_extend = smt_bit_vector_theoryt::sign_extend;
833
+ std::string type_description;
834
+ make_typet make_type;
835
+ make_extensiont make_extension;
836
+ using type_rowt = std::tuple<std::string, make_typet, make_extensiont>;
837
+ std::tie (type_description, make_type, make_extension) = GENERATE_REF (
838
+ type_rowt{" Unsigned operands." , make_unsigned, zero_extend},
839
+ type_rowt{" Signed operands." , make_signed, sign_extend});
840
+ SECTION (type_description)
841
+ {
842
+ using make_shift_exprt = std::function<exprt (exprt, exprt)>;
843
+ const make_shift_exprt left_shift_expr = constructor_of<shl_exprt>();
844
+ const make_shift_exprt arithmetic_right_shift_expr =
845
+ constructor_of<ashr_exprt>();
846
+ const make_shift_exprt logical_right_shift_expr =
847
+ constructor_of<lshr_exprt>();
848
+ using make_shift_termt = std::function<smt_termt (smt_termt, smt_termt)>;
849
+ const make_shift_termt left_shift_term = smt_bit_vector_theoryt::shift_left;
850
+ const make_shift_termt arithmetic_right_shift_term =
851
+ smt_bit_vector_theoryt::arithmetic_shift_right;
852
+ const make_shift_termt logical_right_shift_term =
853
+ smt_bit_vector_theoryt::logical_shift_right;
854
+ std::string shift_description;
855
+ make_shift_exprt make_shift_expr;
856
+ make_shift_termt make_shift_term;
857
+ using shift_rowt =
858
+ std::tuple<std::string, make_shift_exprt, make_shift_termt>;
859
+ std::tie (shift_description, make_shift_expr, make_shift_term) =
860
+ GENERATE_REF (
861
+ shift_rowt{" Left shift." , left_shift_expr, left_shift_term},
862
+ shift_rowt{
863
+ " Arithmetic right shift." ,
864
+ arithmetic_right_shift_expr,
865
+ arithmetic_right_shift_term},
866
+ shift_rowt{
867
+ " Logical right shift." ,
868
+ logical_right_shift_expr,
869
+ logical_right_shift_term});
870
+ SECTION (shift_description)
871
+ {
872
+ SECTION (" Wider left hand side" )
873
+ {
874
+ const exprt input = make_shift_expr (
875
+ symbol_exprt{" foo" , make_type (32 )},
876
+ symbol_exprt{" bar" , make_type (8 )});
877
+ INFO (" Input expr: " + input.pretty (2 , 0 ));
878
+ const smt_termt expected_result = make_shift_term (
879
+ smt_identifier_termt{" foo" , smt_bit_vector_sortt{32 }},
880
+ make_extension (24 )(
881
+ smt_identifier_termt{" bar" , smt_bit_vector_sortt{8 }}));
882
+ CHECK (convert_expr_to_smt (input) == expected_result);
883
+ }
884
+ SECTION (" Wider right hand side" )
885
+ {
886
+ const exprt input = make_shift_expr (
887
+ symbol_exprt{" foo" , make_type (8 )},
888
+ symbol_exprt{" bar" , make_type (32 )});
889
+ INFO (" Input expr: " + input.pretty (2 , 0 ));
890
+ const smt_termt expected_result = make_shift_term (
891
+ make_extension (24 )(
892
+ smt_identifier_termt{" foo" , smt_bit_vector_sortt{8 }}),
893
+ smt_identifier_termt{" bar" , smt_bit_vector_sortt{32 }});
894
+ CHECK (convert_expr_to_smt (input) == expected_result);
895
+ }
896
+ }
897
+ }
898
+ }
899
+
900
+ TEST_CASE (
901
+ " expr to smt conversion for extract bits expressions" ,
902
+ " [core][smt2_incremental]" )
903
+ {
904
+ const typet operand_type = unsignedbv_typet{8 };
905
+ const exprt input = extractbits_exprt{
906
+ symbol_exprt{" foo" , operand_type},
907
+ from_integer (4 , operand_type),
908
+ from_integer (2 , operand_type),
909
+ unsignedbv_typet{3 }};
910
+ const smt_termt expected_result = smt_bit_vector_theoryt::extract (4 , 2 )(
911
+ smt_identifier_termt{" foo" , smt_bit_vector_sortt{8 }});
912
+ CHECK (convert_expr_to_smt (input) == expected_result);
913
+ const cbmc_invariants_should_throwt invariants_throw;
914
+ CHECK_THROWS (convert_expr_to_smt (extractbits_exprt{
915
+ symbol_exprt{" foo" , operand_type},
916
+ symbol_exprt{" bar" , operand_type},
917
+ symbol_exprt{" bar" , operand_type},
918
+ unsignedbv_typet{3 }}));
919
+ }
920
+
822
921
TEST_CASE (" expr to smt conversion for type casts" , " [core][smt2_incremental]" )
823
922
{
824
923
const symbol_exprt bool_expr{" foo" , bool_typet{}};
0 commit comments