@@ -31,10 +31,39 @@ static mp_integer max_int(const std::size_t bits)
3131 return power2 (bits) - 1 ;
3232}
3333
34+ static type_symbolt make_c_enum_type_symbol (std::size_t underlying_size)
35+ {
36+ const signedbv_typet underlying_type{underlying_size};
37+ c_enum_typet enum_type{underlying_type};
38+
39+ auto &members = enum_type.add (ID_body).get_sub ();
40+
41+ for (unsigned int i = 0 ; i < 20 ; ++i)
42+ {
43+ c_enum_typet::c_enum_membert member;
44+ member.set_identifier (" V" + std::to_string (i));
45+ member.set_base_name (" V" + std::to_string (i));
46+ member.set_value (integer2bvrep (i, underlying_size));
47+ members.push_back (member);
48+ }
49+ return type_symbolt{" my_enum" , enum_type, ID_C};
50+ }
51+
52+ static symbolt make_c_enum_tag_instance_symbol (const symbolt &enum_type_symbol)
53+ {
54+ const c_enum_tag_typet enum_tag{enum_type_symbol.name };
55+ return symbolt{" my_enum_value" , enum_tag, ID_C};
56+ }
57+
3458TEST_CASE (" Value expr construction from smt." , " [core][smt2_incremental]" )
3559{
36- const symbol_tablet symbol_table;
60+ symbol_tablet symbol_table;
3761 const namespacet ns{symbol_table};
62+ const symbolt enum_type_symbol = make_c_enum_type_symbol (42 );
63+ const symbolt enum_tag_value_symbol =
64+ make_c_enum_tag_instance_symbol (enum_type_symbol);
65+ symbol_table.insert (enum_type_symbol);
66+ symbol_table.insert (enum_tag_value_symbol);
3867 optionalt<smt_termt> input_term;
3968 optionalt<exprt> expected_result;
4069
@@ -66,7 +95,7 @@ TEST_CASE("Value expr construction from smt.", "[core][smt2_incremental]")
6695 from_integer (-1 , signedbv_typet{(bits)})}
6796 // clang-format on
6897
69- std::tie (input_term, expected_result) = GENERATE (
98+ std::tie (input_term, expected_result) = GENERATE_REF (
7099 rowt{smt_bool_literal_termt{true }, true_exprt{}},
71100 rowt{smt_bool_literal_termt{false }, false_exprt{}},
72101 rowt{smt_bit_vector_constant_termt{0 , 8 }, from_integer (0 , c_bool_typet (8 ))},
@@ -81,6 +110,9 @@ TEST_CASE("Value expr construction from smt.", "[core][smt2_incremental]")
81110 smt_bit_vector_constant_termt{12 , 64 },
82111 constant_exprt (
83112 integer2bvrep (12 , 64 ), pointer_typet (void_type (), 64 /* bits */ ))},
113+ rowt{
114+ smt_bit_vector_constant_termt{2 , 42 },
115+ constant_exprt{" 2" , c_enum_tag_typet{enum_type_symbol.name }}},
84116 UNSIGNED_BIT_VECTOR_TESTS (8 ),
85117 SIGNED_BIT_VECTOR_TESTS (8 ),
86118 UNSIGNED_BIT_VECTOR_TESTS (16 ),
@@ -103,14 +135,19 @@ TEST_CASE(
103135 " Invariant violations in value expr construction from smt." ,
104136 " [core][smt2_incremental]" )
105137{
106- const symbol_tablet symbol_table;
138+ symbol_tablet symbol_table;
107139 const namespacet ns{symbol_table};
140+ const symbolt enum_type_symbol = make_c_enum_type_symbol (5 );
141+ const symbolt enum_tag_value_symbol =
142+ make_c_enum_tag_instance_symbol (enum_type_symbol);
143+ symbol_table.insert (enum_type_symbol);
144+ symbol_table.insert (enum_tag_value_symbol);
108145 optionalt<smt_termt> input_term;
109146 optionalt<typet> input_type;
110147 std::string invariant_reason;
111148
112149 using rowt = std::tuple<smt_termt, typet, std::string>;
113- std::tie (input_term, input_type, invariant_reason) = GENERATE (
150+ std::tie (input_term, input_type, invariant_reason) = GENERATE_REF (
114151 rowt{
115152 smt_bool_literal_termt{true },
116153 unsignedbv_typet{16 },
@@ -147,7 +184,17 @@ TEST_CASE(
147184 rowt{
148185 smt_bit_vector_constant_termt{0 , 16 },
149186 pointer_typet{unsigned_int_type (), 0 },
150- " Width of smt bit vector term must match the width of pointer type" });
187+ " Width of smt bit vector term must match the width of pointer type" },
188+ rowt{
189+ smt_bit_vector_constant_termt{2 , 42 },
190+ c_enum_tag_typet{" foo" },
191+ " we are assuming that a name exists in the namespace when this function "
192+ " is called - identifier foo was not found" },
193+ rowt{
194+ smt_bit_vector_constant_termt{8796093022208ul , 64 },
195+ enum_tag_value_symbol.type ,
196+ " Width of smt bit vector term must match the width of bit vector "
197+ " underlying type of the original c_enum type." });
151198 SECTION (invariant_reason)
152199 {
153200 const cbmc_invariants_should_throwt invariants_throw;
0 commit comments