Skip to content

Commit dbe6455

Browse files
committed
Dump-C: do not produce c_bit_field declarations
goto-program conversion may introduce temporaries of c_bit_field type. These, however, are not permitted outside structs in C. Instead, change their types to their underlying types and use a bit mask to fix up initial values.
1 parent 2e0fcc8 commit dbe6455

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/goto-instrument/goto_program2code.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Author: Daniel Kroening, [email protected]
1212
#include "goto_program2code.h"
1313

1414
#include <util/arith_tools.h>
15+
#include <util/bitvector_expr.h>
1516
#include <util/c_types.h>
1617
#include <util/expr_util.h>
1718
#include <util/ieee_float.h>
@@ -1435,6 +1436,19 @@ void goto_program2codet::cleanup_code(
14351436

14361437
if(code.op0().type().id()==ID_array)
14371438
cleanup_expr(to_array_type(code.op0().type()).size(), true);
1439+
else if(code.op0().type().id() == ID_c_bit_field)
1440+
{
1441+
c_bit_field_typet original_type = to_c_bit_field_type(code.op0().type());
1442+
bitvector_typet bv_type =
1443+
to_bitvector_type(original_type.underlying_type());
1444+
code.op0().type() = bv_type;
1445+
if(code.operands().size() == 2)
1446+
{
1447+
exprt bit_mask =
1448+
from_integer(power(2, original_type.get_width()) - 1, bv_type);
1449+
code.op1() = bitand_exprt{code.op1(), bit_mask};
1450+
}
1451+
}
14381452

14391453
add_local_types(code.op0().type());
14401454

0 commit comments

Comments
 (0)