@@ -1078,7 +1078,7 @@ typet c_typecheck_baset::enum_constant_type(
1078
1078
}
1079
1079
}
1080
1080
1081
- typet c_typecheck_baset::enum_underlying_type (
1081
+ bitvector_typet c_typecheck_baset::enum_underlying_type (
1082
1082
const mp_integer &min_value,
1083
1083
const mp_integer &max_value,
1084
1084
bool is_packed) const
@@ -1216,6 +1216,8 @@ void c_typecheck_baset::typecheck_c_enum_type(typet &type)
1216
1216
c_enum_typet::c_enum_membert member;
1217
1217
member.set_identifier (identifier);
1218
1218
member.set_base_name (base_name);
1219
+ // Note: The value will be correctly set to a bv type when we know
1220
+ // the width of the bitvector
1219
1221
member.set_value (integer2string (value));
1220
1222
enum_members.push_back (member);
1221
1223
@@ -1229,6 +1231,20 @@ void c_typecheck_baset::typecheck_c_enum_type(typet &type)
1229
1231
1230
1232
bool is_packed=type.get_bool (ID_C_packed);
1231
1233
1234
+ // We use a subtype to store the underlying type.
1235
+ bitvector_typet underlying_type =
1236
+ enum_underlying_type (min_value, max_value, is_packed);
1237
+
1238
+ // Get the width to make the values have a bitvector type
1239
+ std::size_t width = underlying_type.get_width ();
1240
+ for (auto &member : enum_members)
1241
+ {
1242
+ // Note: This is inefficient as it first turns integers to strings
1243
+ // and then turns them back to bvrep
1244
+ auto value = string2integer (id2string (member.get_value ()));
1245
+ member.set_value (integer2bvrep (value, width));
1246
+ }
1247
+
1232
1248
// tag?
1233
1249
if (type.find (ID_tag).is_nil ())
1234
1250
{
@@ -1269,10 +1285,6 @@ void c_typecheck_baset::typecheck_c_enum_type(typet &type)
1269
1285
for (const auto &member : enum_members)
1270
1286
body.push_back (member);
1271
1287
1272
- // We use a subtype to store the underlying type.
1273
- typet underlying_type=
1274
- enum_underlying_type (min_value, max_value, is_packed);
1275
-
1276
1288
enum_tag_symbol.type .subtype ()=underlying_type;
1277
1289
1278
1290
// is it in the symbol table already?
0 commit comments