@@ -56,6 +56,24 @@ static boundst map_bounds(
56
56
return result;
57
57
}
58
58
59
+ // / changes the width of the given bitvector type
60
+ bitvector_typet adjust_width (const typet &src, std::size_t new_width)
61
+ {
62
+ if (src.id () == ID_unsignedbv)
63
+ return unsignedbv_typet (new_width);
64
+ else if (src.id () == ID_signedbv)
65
+ return signedbv_typet (new_width);
66
+ else if (src.id () == ID_bv)
67
+ return bv_typet (new_width);
68
+ else if (src.id () == ID_c_enum) // we use the underlying type
69
+ return adjust_width (to_c_enum_type (src).underlying_type (), new_width);
70
+ else if (src.id () == ID_c_bit_field)
71
+ return c_bit_field_typet (
72
+ to_c_bit_field_type (src).underlying_type (), new_width);
73
+ else
74
+ PRECONDITION (false );
75
+ }
76
+
59
77
// / Convert a bitvector-typed expression \p bitvector_expr to a struct-typed
60
78
// / expression. See \ref bv_to_expr for an overview.
61
79
static struct_exprt bv_to_struct_expr (
@@ -89,7 +107,7 @@ static struct_exprt bv_to_struct_expr(
89
107
endianness_map,
90
108
member_offset_bits,
91
109
member_offset_bits + component_bits - 1 );
92
- bitvector_typet type{ bitvector_expr.type (). id () , component_bits} ;
110
+ bitvector_typet type = adjust_width ( bitvector_expr.type (), component_bits) ;
93
111
operands.push_back (bv_to_expr (
94
112
extractbits_exprt{bitvector_expr, bounds.ub , bounds.lb , std::move (type)},
95
113
comp.type (),
@@ -133,7 +151,7 @@ static union_exprt bv_to_union_expr(
133
151
}
134
152
135
153
const auto bounds = map_bounds (endianness_map, 0 , component_bits - 1 );
136
- bitvector_typet type{ bitvector_expr.type (). id () , component_bits} ;
154
+ bitvector_typet type = adjust_width ( bitvector_expr.type (), component_bits) ;
137
155
const irep_idt &component_name = widest_member.has_value ()
138
156
? widest_member->first .get_name ()
139
157
: components.front ().get_name ();
@@ -185,7 +203,8 @@ static array_exprt bv_to_array_expr(
185
203
numeric_cast_v<std::size_t >(*subtype_bits);
186
204
const auto bounds = map_bounds (
187
205
endianness_map, i * subtype_bits_int, ((i + 1 ) * subtype_bits_int) - 1 );
188
- bitvector_typet type{bitvector_expr.type ().id (), subtype_bits_int};
206
+ bitvector_typet type =
207
+ adjust_width (bitvector_expr.type (), subtype_bits_int);
189
208
operands.push_back (bv_to_expr (
190
209
extractbits_exprt{
191
210
bitvector_expr, bounds.ub , bounds.lb , std::move (type)},
@@ -230,7 +249,8 @@ static vector_exprt bv_to_vector_expr(
230
249
numeric_cast_v<std::size_t >(*subtype_bits);
231
250
const auto bounds = map_bounds (
232
251
endianness_map, i * subtype_bits_int, ((i + 1 ) * subtype_bits_int) - 1 );
233
- bitvector_typet type{bitvector_expr.type ().id (), subtype_bits_int};
252
+ bitvector_typet type =
253
+ adjust_width (bitvector_expr.type (), subtype_bits_int);
234
254
operands.push_back (bv_to_expr (
235
255
extractbits_exprt{
236
256
bitvector_expr, bounds.ub , bounds.lb , std::move (type)},
@@ -274,7 +294,8 @@ static complex_exprt bv_to_complex_expr(
274
294
const auto bounds_imag =
275
295
map_bounds (endianness_map, subtype_bits, subtype_bits * 2 - 1 );
276
296
277
- const bitvector_typet type{bitvector_expr.type ().id (), subtype_bits};
297
+ const bitvector_typet type =
298
+ adjust_width (bitvector_expr.type (), subtype_bits);
278
299
279
300
return complex_exprt{
280
301
bv_to_expr (
@@ -1293,7 +1314,7 @@ exprt lower_byte_extract(const byte_extract_exprt &src, const namespacet &ns)
1293
1314
else // width_bytes>=2
1294
1315
{
1295
1316
concatenation_exprt concatenation (
1296
- std::move (op), bitvector_typet ( subtype-> id () , width_bytes * 8 ));
1317
+ std::move (op), adjust_width (* subtype, width_bytes * 8 ));
1297
1318
1298
1319
endianness_mapt map (concatenation.type (), little_endian, ns);
1299
1320
return bv_to_expr (concatenation, src.type (), map, ns);
@@ -2304,12 +2325,11 @@ exprt lower_byte_update(const byte_update_exprt &src, const namespacet &ns)
2304
2325
extractbits_exprt extra_bits{
2305
2326
src.op (), bounds.ub , bounds.lb , bv_typet{n_extra_bits}};
2306
2327
2307
- update_value =
2308
- concatenation_exprt{typecast_exprt::conditional_cast (
2309
- update_value, bv_typet{update_bits_int}),
2310
- extra_bits,
2311
- bitvector_typet{update_value.type ().id (),
2312
- update_bits_int + n_extra_bits}};
2328
+ update_value = concatenation_exprt{
2329
+ typecast_exprt::conditional_cast (
2330
+ update_value, bv_typet{update_bits_int}),
2331
+ extra_bits,
2332
+ adjust_width (update_value.type (), update_bits_int + n_extra_bits)};
2313
2333
}
2314
2334
else
2315
2335
{
0 commit comments