Skip to content

Commit 1ca18f2

Browse files
authored
Merge pull request #8229 from tautschnig/cleanup/no-follow-goto-instrument
goto-instrument: Replace uses of namespacet::follow
2 parents 37a2a8e + ed0e432 commit 1ca18f2

File tree

2 files changed

+32
-13
lines changed

2 files changed

+32
-13
lines changed

src/goto-instrument/dump_c.cpp

+29-10
Original file line numberDiff line numberDiff line change
@@ -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
{

src/goto-instrument/goto_program2code.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1380,8 +1380,6 @@ void goto_program2codet::add_local_types(const typet &type)
13801380
{
13811381
if(type.id() == ID_struct_tag || type.id() == ID_union_tag)
13821382
{
1383-
const typet &full_type=ns.follow(type);
1384-
13851383
const irep_idt &identifier = to_tag_type(type).get_identifier();
13861384
const symbolt &symbol = ns.lookup(identifier);
13871385

@@ -1390,7 +1388,9 @@ void goto_program2codet::add_local_types(const typet &type)
13901388
!type_names_set.insert(identifier).second)
13911389
return;
13921390

1393-
for(const auto &c : to_struct_union_type(full_type).components())
1391+
const auto &components =
1392+
ns.follow_tag(to_struct_or_union_tag_type(type)).components();
1393+
for(const auto &c : components)
13941394
add_local_types(c.type());
13951395

13961396
type_names.push_back(identifier);

0 commit comments

Comments
 (0)