Skip to content

Commit 8745e42

Browse files
authored
Merge pull request #5799 from tautschnig/dump-union3
dump-c: handle further byte_update union initializers
2 parents 3b406c6 + cfeb536 commit 8745e42

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ union U6 {
1919

2020
union U6 g_1197 = {1L};
2121

22+
union U4 {
23+
signed f0 : 6;
24+
int f3;
25+
};
26+
27+
union U4 g_1408 = {-1L};
28+
2229
int main()
2330
{
2431
assert(g_2110.f0 == 53747);

src/goto-instrument/dump_c.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,7 +1450,8 @@ void dump_ct::cleanup_expr(exprt &expr)
14501450
ID_initializer_list,
14511451
std::move(designated_initializer2)};
14521452
expr.swap(initializer_list);
1453-
break;
1453+
1454+
return;
14541455
}
14551456
}
14561457
}
@@ -1467,11 +1468,13 @@ void dump_ct::cleanup_expr(exprt &expr)
14671468
{
14681469
union_exprt union_expr{comp.get_name(), bu.value(), bu.op().type()};
14691470
expr.swap(union_expr);
1470-
break;
1471+
1472+
return;
14711473
}
14721474
}
14731475
}
1474-
else if(
1476+
1477+
if(
14751478
ns.follow(bu.type()).id() == ID_union &&
14761479
bu.source_location().get_function().empty() &&
14771480
bu.op() == zero_initializer(bu.op().type(), source_locationt{}, ns)
@@ -1485,9 +1488,14 @@ void dump_ct::cleanup_expr(exprt &expr)
14851488
{
14861489
union_exprt union_expr{comp.get_name(), bu.value(), bu.type()};
14871490
expr.swap(union_expr);
1488-
break;
1491+
1492+
return;
14891493
}
14901494
}
1495+
1496+
// we still haven't found a suitable component, so just ignore types and
1497+
// build an initializer list without designators
1498+
expr = unary_exprt{ID_initializer_list, bu.value()};
14911499
}
14921500
}
14931501
}

0 commit comments

Comments
 (0)