@@ -573,7 +573,10 @@ void dump_ct::convert_compound(
573573 typet comp_type_to_use = comp.type ();
574574 if (is_anon)
575575 {
576- comp_type_to_use = ns.follow (comp.type ());
576+ comp_type_to_use =
577+ (comp.type ().id () == ID_struct_tag || comp.type ().id () == ID_union_tag)
578+ ? ns.follow_tag (to_struct_or_union_tag_type (comp.type ()))
579+ : comp.type ();
577580 comp_type_to_use.remove (ID_tag);
578581 if (
579582 recursive && (comp_type_to_use.id () == ID_struct ||
@@ -1353,8 +1356,9 @@ void dump_ct::cleanup_expr(exprt &expr)
13531356
13541357 if (expr.id ()==ID_struct)
13551358 {
1356- struct_typet type=
1357- to_struct_type (ns.follow (expr.type ()));
1359+ struct_typet type = expr.type ().id () == ID_struct_tag
1360+ ? ns.follow_tag (to_struct_tag_type (expr.type ()))
1361+ : to_struct_type (expr.type ());
13581362
13591363 struct_union_typet::componentst old_components;
13601364 old_components.swap (type.components ());
@@ -1382,7 +1386,9 @@ void dump_ct::cleanup_expr(exprt &expr)
13821386 else if (expr.id ()==ID_union)
13831387 {
13841388 union_exprt &u=to_union_expr (expr);
1385- const union_typet &u_type_f=to_union_type (ns.follow (u.type ()));
1389+ const union_typet &u_type_f = u.type ().id () == ID_union_tag
1390+ ? ns.follow_tag (to_union_tag_type (u.type ()))
1391+ : to_union_type (u.type ());
13861392
13871393 if (!u.type ().get_bool (ID_C_transparent_union) &&
13881394 !u_type_f.get_bool (ID_C_transparent_union))
@@ -1440,7 +1446,10 @@ void dump_ct::cleanup_expr(exprt &expr)
14401446 code_typet::parameterst::const_iterator it=parameters.begin ();
14411447 for (auto &argument : arguments)
14421448 {
1443- const typet &type=ns.follow (it->type ());
1449+ const typet &type = it->type ().id () == ID_union_tag
1450+ ? static_cast <const typet &>(ns.follow_tag (
1451+ to_union_tag_type (it->type ())))
1452+ : it->type ();
14441453 if (type.id ()==ID_union &&
14451454 type.get_bool (ID_C_transparent_union))
14461455 {
@@ -1494,7 +1503,9 @@ void dump_ct::cleanup_expr(exprt &expr)
14941503 {
14951504 const union_exprt &union_expr = to_union_expr (bu.op ());
14961505 const union_typet &union_type =
1497- to_union_type (ns.follow (union_expr.type ()));
1506+ union_expr.type ().id () == ID_union_tag
1507+ ? ns.follow_tag (to_union_tag_type (union_expr.type ()))
1508+ : to_union_type (union_expr.type ());
14981509
14991510 for (const auto &comp : union_type.components ())
15001511 {
@@ -1524,9 +1535,14 @@ void dump_ct::cleanup_expr(exprt &expr)
15241535 else if (
15251536 bu.op ().id () == ID_side_effect &&
15261537 to_side_effect_expr (bu.op ()).get_statement () == ID_nondet &&
1527- ns.follow (bu.op ().type ()).id () == ID_union && bu.offset ().is_zero ())
1538+ (bu.op ().type ().id () == ID_union ||
1539+ bu.op ().type ().id () == ID_union_tag) &&
1540+ bu.offset ().is_zero ())
15281541 {
1529- const union_typet &union_type = to_union_type (ns.follow (bu.op ().type ()));
1542+ const union_typet &union_type =
1543+ bu.op ().type ().id () == ID_union_tag
1544+ ? ns.follow_tag (to_union_tag_type (bu.op ().type ()))
1545+ : to_union_type (bu.op ().type ());
15301546
15311547 for (const auto &comp : union_type.components ())
15321548 {
@@ -1542,7 +1558,7 @@ void dump_ct::cleanup_expr(exprt &expr)
15421558
15431559 std::optional<exprt> clean_init;
15441560 if (
1545- ns. follow (bu.type ()) .id () == ID_union &&
1561+ (bu.type ().id () == ID_union || bu. type (). id () == ID_union_tag) &&
15461562 bu.source_location ().get_function ().empty ())
15471563 {
15481564 clean_init = zero_initializer (bu.op ().type (), source_locationt{}, ns)
@@ -1553,7 +1569,10 @@ void dump_ct::cleanup_expr(exprt &expr)
15531569
15541570 if (clean_init.has_value () && bu.op () == *clean_init)
15551571 {
1556- const union_typet &union_type = to_union_type (ns.follow (bu.type ()));
1572+ const union_typet &union_type =
1573+ bu.type ().id () == ID_union_tag
1574+ ? ns.follow_tag (to_union_tag_type (bu.type ()))
1575+ : to_union_type (bu.type ());
15571576
15581577 for (const auto &comp : union_type.components ())
15591578 {
0 commit comments