@@ -29,6 +29,8 @@ Function: alignment
2929
3030mp_integer alignment (const typet &type, const namespacet &ns)
3131{
32+ const unsigned bits=config.ansi_c .char_width ;
33+
3234 // we need to consider a number of different cases:
3335 // - alignment specified in the source, which will be recorded in
3436 // ID_C_alignment
@@ -85,7 +87,7 @@ mp_integer alignment(const typet &type, const namespacet &ns)
8587 type.id ()==ID_c_bool)
8688 {
8789 std::size_t width=to_bitvector_type (type).get_width ();
88- result=width%8 ?width/8 +1 :width/8 ;
90+ result=width%bits ?width/bits +1 :width/bits ;
8991 }
9092 else if (type.id ()==ID_c_enum)
9193 result=alignment (type.subtype (), ns);
@@ -94,7 +96,7 @@ mp_integer alignment(const typet &type, const namespacet &ns)
9496 else if (type.id ()==ID_pointer)
9597 {
9698 std::size_t width=config.ansi_c .pointer_width ;
97- result=width%8 ?width/8 +1 :width/8 ;
99+ result=width%bits ?width/bits +1 :width/bits ;
98100 }
99101 else if (type.id ()==ID_symbol)
100102 result=alignment (ns.follow (type), ns);
@@ -152,9 +154,10 @@ void add_padding(struct_typet &type, const namespacet &ns)
152154 else if (bit_field_bits!=0 )
153155 {
154156 // not on a byte-boundary?
155- if ((bit_field_bits%8 )!=0 )
157+ if ((bit_field_bits%config. ansi_c . char_width )!=0 )
156158 {
157- std::size_t pad=8 -bit_field_bits%8 ;
159+ std::size_t pad=
160+ config.ansi_c .char_width -bit_field_bits%config.ansi_c .char_width ;
158161 c_bit_field_typet padding_type (unsignedbv_typet (pad), pad);
159162
160163 struct_typet::componentt component;
@@ -174,9 +177,10 @@ void add_padding(struct_typet &type, const namespacet &ns)
174177 }
175178
176179 // Add padding at the end?
177- if ((bit_field_bits%8 )!=0 )
180+ if ((bit_field_bits%config. ansi_c . char_width )!=0 )
178181 {
179- std::size_t pad=8 -bit_field_bits%8 ;
182+ std::size_t pad=
183+ config.ansi_c .char_width -bit_field_bits%config.ansi_c .char_width ;
180184 c_bit_field_typet padding_type (unsignedbv_typet (pad), pad);
181185
182186 struct_typet::componentt component;
@@ -225,8 +229,12 @@ void add_padding(struct_typet &type, const namespacet &ns)
225229 max_alignment=a;
226230
227231 std::size_t w=to_c_bit_field_type (it_type).get_width ();
228- std::size_t bytes;
229- for (bytes=0 ; w>bit_field_bits; ++bytes, bit_field_bits+=8 ) {}
232+ std::size_t bytes=0 ;
233+ while (w>bit_field_bits)
234+ {
235+ ++bytes;
236+ bit_field_bits+=config.ansi_c .char_width ;
237+ }
230238 bit_field_bits-=w;
231239 offset+=bytes;
232240 continue ;
@@ -252,7 +260,7 @@ void add_padding(struct_typet &type, const namespacet &ns)
252260 mp_integer pad=a-displacement;
253261
254262 unsignedbv_typet padding_type;
255- padding_type.set_width (integer2unsigned (pad*8 ));
263+ padding_type.set_width (integer2unsigned (pad*config. ansi_c . char_width ));
256264
257265 struct_typet::componentt component;
258266 component.type ()=padding_type;
@@ -274,8 +282,8 @@ void add_padding(struct_typet &type, const namespacet &ns)
274282
275283 if (bit_field_bits!=0 )
276284 {
277- // these are now assumed to be multiples of 8
278- offset+=bit_field_bits/8 ;
285+ // these are now assumed to be multiples of bytes
286+ offset+=bit_field_bits/config. ansi_c . char_width ;
279287 }
280288
281289 // any explicit alignment for the struct?
@@ -309,7 +317,7 @@ void add_padding(struct_typet &type, const namespacet &ns)
309317 mp_integer pad=max_alignment-displacement;
310318
311319 unsignedbv_typet padding_type;
312- padding_type.set_width (integer2unsigned (pad*8 ));
320+ padding_type.set_width (integer2unsigned (pad*config. ansi_c . char_width ));
313321
314322 // we insert after any final 'flexible member'
315323 struct_typet::componentt component;
@@ -336,16 +344,16 @@ Function: add_padding
336344
337345void add_padding (union_typet &type, const namespacet &ns)
338346{
339- mp_integer max_alignment=alignment (type, ns)*8 ;
347+ mp_integer max_alignment=alignment (type, ns)*config. ansi_c . char_width ;
340348 mp_integer size_bits=pointer_offset_bits (type, ns);
341349
342350 union_typet::componentst &components=type.components ();
343351
344352 // Is the union packed?
345353 if (type.get_bool (ID_C_packed))
346354 {
347- // The size needs to be a multiple of 8 only.
348- max_alignment=8 ;
355+ // The size needs to be a multiple of bytes only.
356+ max_alignment=config. ansi_c . char_width ;
349357 }
350358
351359 // The size must be a multiple of the alignment, or
0 commit comments