@@ -31,10 +31,39 @@ static mp_integer max_int(const std::size_t bits)
31
31
return power2 (bits) - 1 ;
32
32
}
33
33
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
+
34
58
TEST_CASE (" Value expr construction from smt." , " [core][smt2_incremental]" )
35
59
{
36
- const symbol_tablet symbol_table;
60
+ symbol_tablet symbol_table;
37
61
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);
38
67
optionalt<smt_termt> input_term;
39
68
optionalt<exprt> expected_result;
40
69
@@ -66,7 +95,7 @@ TEST_CASE("Value expr construction from smt.", "[core][smt2_incremental]")
66
95
from_integer (-1 , signedbv_typet{(bits)})}
67
96
// clang-format on
68
97
69
- std::tie (input_term, expected_result) = GENERATE (
98
+ std::tie (input_term, expected_result) = GENERATE_REF (
70
99
rowt{smt_bool_literal_termt{true }, true_exprt{}},
71
100
rowt{smt_bool_literal_termt{false }, false_exprt{}},
72
101
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]")
81
110
smt_bit_vector_constant_termt{12 , 64 },
82
111
constant_exprt (
83
112
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 }}},
84
116
UNSIGNED_BIT_VECTOR_TESTS (8 ),
85
117
SIGNED_BIT_VECTOR_TESTS (8 ),
86
118
UNSIGNED_BIT_VECTOR_TESTS (16 ),
@@ -103,14 +135,19 @@ TEST_CASE(
103
135
" Invariant violations in value expr construction from smt." ,
104
136
" [core][smt2_incremental]" )
105
137
{
106
- const symbol_tablet symbol_table;
138
+ symbol_tablet symbol_table;
107
139
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);
108
145
optionalt<smt_termt> input_term;
109
146
optionalt<typet> input_type;
110
147
std::string invariant_reason;
111
148
112
149
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 (
114
151
rowt{
115
152
smt_bool_literal_termt{true },
116
153
unsignedbv_typet{16 },
@@ -147,7 +184,17 @@ TEST_CASE(
147
184
rowt{
148
185
smt_bit_vector_constant_termt{0 , 16 },
149
186
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." });
151
198
SECTION (invariant_reason)
152
199
{
153
200
const cbmc_invariants_should_throwt invariants_throw;
0 commit comments