Skip to content

Commit 6779f39

Browse files
committed
dump-c: handle further byte_update union initializers
The CSmith test generated with random seed 1614606277 demonstrated that dump-c's handling still didn't cover all cases of byte_update expressions introduced by the C front-end, specifically missing the case where a struct was part of the union.
1 parent 1828d43 commit 6779f39

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

regression/goto-instrument/dump-union2/main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ union U10 {
1212
};
1313

1414
union U10 g_2110 = {.f0 = 53747};
15+
union U10 g_1256 = {-6L};
1516

1617
union U6 {
1718
signed f0 : 3;

src/goto-instrument/dump_c.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1469,11 +1469,18 @@ void dump_ct::cleanup_expr(exprt &expr)
14691469
}
14701470
}
14711471

1472+
optionalt<exprt> clean_init;
14721473
if(
14731474
ns.follow(bu.type()).id() == ID_union &&
1474-
bu.source_location().get_function().empty() &&
1475-
bu.op() == zero_initializer(bu.op().type(), source_locationt{}, ns)
1476-
.value_or(nil_exprt{}))
1475+
bu.source_location().get_function().empty())
1476+
{
1477+
clean_init = zero_initializer(bu.op().type(), source_locationt{}, ns)
1478+
.value_or(nil_exprt{});
1479+
if(clean_init->id() != ID_struct || clean_init->has_operands())
1480+
cleanup_expr(*clean_init);
1481+
}
1482+
1483+
if(clean_init.has_value() && bu.op() == *clean_init)
14771484
{
14781485
const union_typet &union_type = to_union_type(ns.follow(bu.type()));
14791486

0 commit comments

Comments
 (0)