Skip to content

Commit 62f0be3

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 8ea700e commit 62f0be3

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,12 @@ 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 &&
195+
underlying_bits == config.ansi_c.char_width)
196+
{
197+
++bit_field_bits;
198+
}
193199
else
194200
{
195201
// pad up any remaining bit field
@@ -201,6 +207,8 @@ static void add_padding_msvc(struct_typet &type, const namespacet &ns)
201207
offset += (bit_field_bits + pad_bits) / config.ansi_c.char_width;
202208
underlying_bits = bit_field_bits = 0;
203209
}
210+
else
211+
offset += underlying_bits / config.ansi_c.char_width;
204212

205213
// pad up to underlying type unless the struct is packed
206214
if(!is_packed)
@@ -231,6 +239,7 @@ static void add_padding_msvc(struct_typet &type, const namespacet &ns)
231239
}
232240
else if(it->type().id() == ID_bool)
233241
{
242+
underlying_bits = config.ansi_c.char_width;
234243
++bit_field_bits;
235244
}
236245
else
@@ -252,6 +261,8 @@ static void add_padding_msvc(struct_typet &type, const namespacet &ns)
252261
pad_bit_field(components, components.end(), pad);
253262
offset += (bit_field_bits + pad) / config.ansi_c.char_width;
254263
}
264+
else
265+
offset += underlying_bits / config.ansi_c.char_width;
255266

256267
// alignment of the struct
257268
// Note that this is done even if the struct is packed.

0 commit comments

Comments
 (0)