Skip to content

Commit ed53dae

Browse files
committed
Fix bit-field and __CPROVER_bool padding for Visual Studio
Bit fields that sum up to the underlying type need to update the offset to ensure padding suitable for the alignment is inserted.
1 parent 3d4131d commit ed53dae

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

regression/ansi-c/cprover_bool1/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG
1+
CORE
22
main.c
33

44
^EXIT=0$

src/ansi-c/padding.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,11 @@ static void add_padding_msvc(struct_typet &type, const namespacet &ns)
190190
const auto width = to_c_bit_field_type(it->type()).get_width();
191191
bit_field_bits += width;
192192
}
193+
else if(
194+
it->type().id() == ID_bool && underlying_bits == config.ansi_c.char_width)
195+
{
196+
++bit_field_bits;
197+
}
193198
else
194199
{
195200
// pad up any remaining bit field
@@ -201,6 +206,8 @@ static void add_padding_msvc(struct_typet &type, const namespacet &ns)
201206
offset += (bit_field_bits + pad_bits) / config.ansi_c.char_width;
202207
underlying_bits = bit_field_bits = 0;
203208
}
209+
else
210+
offset += underlying_bits / config.ansi_c.char_width;
204211

205212
// pad up to underlying type unless the struct is packed
206213
if(!is_packed)
@@ -231,6 +238,7 @@ static void add_padding_msvc(struct_typet &type, const namespacet &ns)
231238
}
232239
else if(it->type().id() == ID_bool)
233240
{
241+
underlying_bits = config.ansi_c.char_width;
234242
++bit_field_bits;
235243
}
236244
else
@@ -252,6 +260,8 @@ static void add_padding_msvc(struct_typet &type, const namespacet &ns)
252260
pad_bit_field(components, components.end(), pad);
253261
offset += (bit_field_bits + pad) / config.ansi_c.char_width;
254262
}
263+
else
264+
offset += underlying_bits / config.ansi_c.char_width;
255265

256266
// alignment of the struct
257267
// Note that this is done even if the struct is packed.

0 commit comments

Comments
 (0)