Skip to content

Commit 2b2d337

Browse files
committed
util: Replace uses of namespacet::follow
This is deprecated. Use suitable variants of `follow_tag` instead.
1 parent d7b229e commit 2b2d337

7 files changed

+155
-81
lines changed

Diff for: src/util/lower_byte_operators.cpp

+26-14
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,10 @@ static array_exprt unpack_struct(
696696
const std::size_t bits_per_byte,
697697
const namespacet &ns)
698698
{
699-
const struct_typet &struct_type = to_struct_type(ns.follow(src.type()));
699+
const struct_typet &struct_type =
700+
src.type().id() == ID_struct_tag
701+
? ns.follow_tag(to_struct_tag_type(src.type()))
702+
: to_struct_type(src.type());
700703
const struct_typet::componentst &components = struct_type.components();
701704

702705
std::optional<mp_integer> offset_in_member;
@@ -963,7 +966,10 @@ static exprt unpack_rec(
963966
}
964967
else if(src.type().id() == ID_union || src.type().id() == ID_union_tag)
965968
{
966-
const union_typet &union_type = to_union_type(ns.follow(src.type()));
969+
const union_typet &union_type =
970+
src.type().id() == ID_union_tag
971+
? ns.follow_tag(to_union_tag_type(src.type()))
972+
: to_union_type(src.type());
967973

968974
const auto widest_member = union_type.find_widest_union_component(ns);
969975

@@ -1316,7 +1322,10 @@ exprt lower_byte_extract(const byte_extract_exprt &src, const namespacet &ns)
13161322
}
13171323
else if(src.type().id() == ID_struct || src.type().id() == ID_struct_tag)
13181324
{
1319-
const struct_typet &struct_type = to_struct_type(ns.follow(src.type()));
1325+
const struct_typet &struct_type =
1326+
src.type().id() == ID_struct_tag
1327+
? ns.follow_tag(to_struct_tag_type(src.type()))
1328+
: to_struct_type(src.type());
13201329
const struct_typet::componentst &components = struct_type.components();
13211330

13221331
bool failed = false;
@@ -1361,7 +1370,10 @@ exprt lower_byte_extract(const byte_extract_exprt &src, const namespacet &ns)
13611370
}
13621371
else if(src.type().id() == ID_union || src.type().id() == ID_union_tag)
13631372
{
1364-
const union_typet &union_type = to_union_type(ns.follow(src.type()));
1373+
const union_typet &union_type =
1374+
src.type().id() == ID_union_tag
1375+
? ns.follow_tag(to_union_tag_type(src.type()))
1376+
: to_union_type(src.type());
13651377

13661378
const auto widest_member = union_type.find_widest_union_component(ns);
13671379

@@ -2355,23 +2367,23 @@ static exprt lower_byte_update(
23552367
}
23562368
else if(src.type().id() == ID_struct || src.type().id() == ID_struct_tag)
23572369
{
2370+
const struct_typet &struct_type =
2371+
src.type().id() == ID_struct_tag
2372+
? ns.follow_tag(to_struct_tag_type(src.type()))
2373+
: to_struct_type(src.type());
23582374
exprt result = lower_byte_update_struct(
2359-
src,
2360-
to_struct_type(ns.follow(src.type())),
2361-
value_as_byte_array,
2362-
non_const_update_bound,
2363-
ns);
2375+
src, struct_type, value_as_byte_array, non_const_update_bound, ns);
23642376
result.type() = src.type();
23652377
return result;
23662378
}
23672379
else if(src.type().id() == ID_union || src.type().id() == ID_union_tag)
23682380
{
2381+
const union_typet &union_type =
2382+
src.type().id() == ID_union_tag
2383+
? ns.follow_tag(to_union_tag_type(src.type()))
2384+
: to_union_type(src.type());
23692385
exprt result = lower_byte_update_union(
2370-
src,
2371-
to_union_type(ns.follow(src.type())),
2372-
value_as_byte_array,
2373-
non_const_update_bound,
2374-
ns);
2386+
src, union_type, value_as_byte_array, non_const_update_bound, ns);
23752387
result.type() = src.type();
23762388
return result;
23772389
}

Diff for: src/util/pointer_offset_size.cpp

+29-15
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,17 @@ std::optional<exprt>
222222
member_offset_expr(const member_exprt &member_expr, const namespacet &ns)
223223
{
224224
// need to distinguish structs and unions
225-
const typet &type=ns.follow(member_expr.struct_op().type());
226-
if(type.id()==ID_struct)
225+
const typet &compound_type = member_expr.struct_op().type();
226+
if(compound_type.id() == ID_struct || compound_type.id() == ID_struct_tag)
227+
{
228+
const struct_typet &struct_type =
229+
compound_type.id() == ID_struct_tag
230+
? ns.follow_tag(to_struct_tag_type(compound_type))
231+
: to_struct_type(compound_type);
227232
return member_offset_expr(
228-
to_struct_type(type), member_expr.get_component_name(), ns);
229-
else if(type.id()==ID_union)
233+
struct_type, member_expr.get_component_name(), ns);
234+
}
235+
else if(compound_type.id() == ID_union || compound_type.id() == ID_union_tag)
230236
return from_integer(0, size_type());
231237
else
232238
return {};
@@ -544,17 +550,20 @@ compute_pointer_offset(const exprt &expr, const namespacet &ns)
544550
{
545551
const member_exprt &member_expr=to_member_expr(expr);
546552
const exprt &op=member_expr.struct_op();
547-
const struct_union_typet &type=to_struct_union_type(ns.follow(op.type()));
548553

549554
auto o = compute_pointer_offset(op, ns);
550555

551556
if(o.has_value())
552557
{
553-
if(type.id()==ID_union)
558+
if(op.type().id() == ID_union || op.type().id() == ID_union_tag)
554559
return *o;
555560

556-
auto member_offset = ::member_offset(
557-
to_struct_type(type), member_expr.get_component_name(), ns);
561+
const struct_typet &struct_type =
562+
op.type().id() == ID_struct_tag
563+
? ns.follow_tag(to_struct_tag_type(op.type()))
564+
: to_struct_type(op.type());
565+
auto member_offset =
566+
::member_offset(struct_type, member_expr.get_component_name(), ns);
558567

559568
if(member_offset.has_value())
560569
return *o + *member_offset;
@@ -589,14 +598,16 @@ std::optional<exprt> get_subexpression_at_offset(
589598
return typecast_exprt(expr, target_type_raw);
590599
}
591600

592-
const typet &source_type = ns.follow(expr.type());
593601
const auto target_size_bits = pointer_offset_bits(target_type_raw, ns);
594602
if(!target_size_bits.has_value())
595603
return {};
596604

597-
if(source_type.id()==ID_struct)
605+
if(expr.type().id() == ID_struct || expr.type().id() == ID_struct_tag)
598606
{
599-
const struct_typet &struct_type = to_struct_type(source_type);
607+
const struct_typet &struct_type =
608+
expr.type().id() == ID_struct_tag
609+
? ns.follow_tag(to_struct_tag_type(expr.type()))
610+
: to_struct_type(expr.type());
600611

601612
mp_integer m_offset_bits = 0;
602613
for(const auto &component : struct_type.components())
@@ -624,9 +635,9 @@ std::optional<exprt> get_subexpression_at_offset(
624635
m_offset_bits += *m_size_bits;
625636
}
626637
}
627-
else if(source_type.id()==ID_array)
638+
else if(expr.type().id() == ID_array)
628639
{
629-
const array_typet &array_type = to_array_type(source_type);
640+
const array_typet &array_type = to_array_type(expr.type());
630641

631642
const auto elem_size_bits =
632643
pointer_offset_bits(array_type.element_type(), ns);
@@ -663,9 +674,12 @@ std::optional<exprt> get_subexpression_at_offset(
663674
}
664675
else if(
665676
object_descriptor_exprt(expr).root_object().id() == ID_union &&
666-
source_type.id() == ID_union)
677+
(expr.type().id() == ID_union || expr.type().id() == ID_union_tag))
667678
{
668-
const union_typet &union_type = to_union_type(source_type);
679+
const union_typet &union_type =
680+
expr.type().id() == ID_union_tag
681+
? ns.follow_tag(to_union_tag_type(expr.type()))
682+
: to_union_type(expr.type());
669683

670684
for(const auto &component : union_type.components())
671685
{

Diff for: src/util/simplify_expr.cpp

+45-27
Original file line numberDiff line numberDiff line change
@@ -1449,11 +1449,11 @@ simplify_exprt::resultt<> simplify_exprt::simplify_with(const with_exprt &expr)
14491449
// copy
14501450
auto with_expr = expr;
14511451

1452-
const typet old_type_followed = ns.follow(with_expr.old().type());
1453-
14541452
// now look at first operand
14551453

1456-
if(old_type_followed.id() == ID_struct)
1454+
if(
1455+
with_expr.old().type().id() == ID_struct ||
1456+
with_expr.old().type().id() == ID_struct_tag)
14571457
{
14581458
if(with_expr.old().id() == ID_struct || with_expr.old().is_constant())
14591459
{
@@ -1462,11 +1462,14 @@ simplify_exprt::resultt<> simplify_exprt::simplify_with(const with_exprt &expr)
14621462
const irep_idt &component_name =
14631463
with_expr.where().get(ID_component_name);
14641464

1465-
if(!to_struct_type(old_type_followed).has_component(component_name))
1465+
const struct_typet &old_type_followed =
1466+
with_expr.old().type().id() == ID_struct_tag
1467+
? ns.follow_tag(to_struct_tag_type(with_expr.old().type()))
1468+
: to_struct_type(with_expr.old().type());
1469+
if(!old_type_followed.has_component(component_name))
14661470
return unchanged(expr);
14671471

1468-
std::size_t number =
1469-
to_struct_type(old_type_followed).component_number(component_name);
1472+
std::size_t number = old_type_followed.component_number(component_name);
14701473

14711474
if(number >= with_expr.old().operands().size())
14721475
return unchanged(expr);
@@ -1530,8 +1533,6 @@ simplify_exprt::simplify_update(const update_exprt &expr)
15301533

15311534
for(const auto &e : designator)
15321535
{
1533-
const typet &value_ptr_type=ns.follow(value_ptr->type());
1534-
15351536
if(e.id()==ID_index_designator &&
15361537
value_ptr->id()==ID_array)
15371538
{
@@ -1551,7 +1552,9 @@ simplify_exprt::simplify_update(const update_exprt &expr)
15511552
const irep_idt &component_name=
15521553
e.get(ID_component_name);
15531554
const struct_typet &value_ptr_struct_type =
1554-
to_struct_type(value_ptr_type);
1555+
value_ptr->type().id() == ID_struct_tag
1556+
? ns.follow_tag(to_struct_tag_type(value_ptr->type()))
1557+
: to_struct_type(value_ptr->type());
15551558
if(!value_ptr_struct_type.has_component(component_name))
15561559
return unchanged(expr);
15571560
auto &designator_as_struct_expr = to_struct_expr(*value_ptr);
@@ -1788,14 +1791,18 @@ simplify_exprt::simplify_byte_extract(const byte_extract_exprt &expr)
17881791
}
17891792

17901793
if(
1791-
(expr.type().id() == ID_union || expr.type().id() == ID_union_tag) &&
1792-
to_union_type(ns.follow(expr.type())).components().empty())
1794+
(expr.type().id() == ID_union &&
1795+
to_union_type(expr.type()).components().empty()) ||
1796+
(expr.type().id() == ID_union_tag &&
1797+
ns.follow_tag(to_union_tag_type(expr.type())).components().empty()))
17931798
{
17941799
return empty_union_exprt{expr.type()};
17951800
}
17961801
else if(
1797-
(expr.type().id() == ID_struct || expr.type().id() == ID_struct_tag) &&
1798-
to_struct_type(ns.follow(expr.type())).components().empty())
1802+
(expr.type().id() == ID_struct &&
1803+
to_struct_type(expr.type()).components().empty()) ||
1804+
(expr.type().id() == ID_struct_tag &&
1805+
ns.follow_tag(to_struct_tag_type(expr.type())).components().empty()))
17991806
{
18001807
return struct_exprt{{}, expr.type()};
18011808
}
@@ -1870,7 +1877,9 @@ simplify_exprt::simplify_byte_extract(const byte_extract_exprt &expr)
18701877
if(type.id() != ID_struct && type.id() != ID_struct_tag)
18711878
return false;
18721879

1873-
const struct_typet &st = to_struct_type(ns.follow(type));
1880+
const struct_typet &st = type.id() == ID_struct_tag
1881+
? ns.follow_tag(to_struct_tag_type(type))
1882+
: to_struct_type(type);
18741883
const auto &comps = st.components();
18751884
if(comps.empty() || comps.back().type().id() != ID_array)
18761885
return false;
@@ -1905,7 +1914,10 @@ simplify_exprt::simplify_byte_extract(const byte_extract_exprt &expr)
19051914
{
19061915
if(expr.type().id() == ID_struct || expr.type().id() == ID_struct_tag)
19071916
{
1908-
const struct_typet &struct_type = to_struct_type(ns.follow(expr.type()));
1917+
const struct_typet &struct_type =
1918+
expr.type().id() == ID_struct_tag
1919+
? ns.follow_tag(to_struct_tag_type(expr.type()))
1920+
: to_struct_type(expr.type());
19091921
const struct_typet::componentst &components = struct_type.components();
19101922

19111923
bool failed = false;
@@ -1950,7 +1962,10 @@ simplify_exprt::simplify_byte_extract(const byte_extract_exprt &expr)
19501962
}
19511963
else if(expr.type().id() == ID_union || expr.type().id() == ID_union_tag)
19521964
{
1953-
const union_typet &union_type = to_union_type(ns.follow(expr.type()));
1965+
const union_typet &union_type =
1966+
expr.type().id() == ID_union_tag
1967+
? ns.follow_tag(to_union_tag_type(expr.type()))
1968+
: to_union_type(expr.type());
19541969
auto widest_member_opt = union_type.find_widest_union_component(ns);
19551970
if(widest_member_opt.has_value())
19561971
{
@@ -2150,10 +2165,12 @@ simplify_exprt::simplify_byte_update(const byte_update_exprt &expr)
21502165
if(!(offset==extract.offset()))
21512166
return unchanged(expr);
21522167

2153-
const typet &tp=ns.follow(with.type());
2154-
if(tp.id()==ID_struct)
2168+
if(with.type().id() == ID_struct || with.type().id() == ID_struct_tag)
21552169
{
2156-
const struct_typet &struct_type=to_struct_type(tp);
2170+
const struct_typet &struct_type =
2171+
with.type().id() == ID_struct_tag
2172+
? ns.follow_tag(to_struct_tag_type(with.type()))
2173+
: to_struct_type(with.type());
21572174
const irep_idt &component_name=with.where().get(ID_component_name);
21582175
const typet &c_type = struct_type.get_component(component_name).type();
21592176

@@ -2178,9 +2195,10 @@ simplify_exprt::simplify_byte_update(const byte_update_exprt &expr)
21782195
}
21792196
}
21802197
}
2181-
else if(tp.id()==ID_array)
2198+
else if(with.type().id() == ID_array)
21822199
{
2183-
auto i = pointer_offset_size(to_array_type(tp).element_type(), ns);
2200+
auto i =
2201+
pointer_offset_size(to_array_type(with.type()).element_type(), ns);
21842202
if(i.has_value())
21852203
{
21862204
const exprt &index=with.where();
@@ -2209,23 +2227,23 @@ simplify_exprt::simplify_byte_update(const byte_update_exprt &expr)
22092227
if(!offset_int.has_value() || *offset_int < 0)
22102228
return unchanged(expr);
22112229

2212-
const typet &op_type=ns.follow(root.type());
2213-
22142230
// size must be known
22152231
if(!val_size.has_value() || *val_size == 0)
22162232
return unchanged(expr);
22172233

22182234
// Are we updating (parts of) a struct? Do individual member updates
22192235
// instead, unless there are non-byte-sized bit fields
2220-
if(op_type.id()==ID_struct)
2236+
if(root.type().id() == ID_struct || root.type().id() == ID_struct_tag)
22212237
{
22222238
exprt result_expr;
22232239
result_expr.make_nil();
22242240

22252241
auto update_size = pointer_offset_size(value.type(), ns);
22262242

2227-
const struct_typet &struct_type=
2228-
to_struct_type(op_type);
2243+
const struct_typet &struct_type =
2244+
root.type().id() == ID_struct_tag
2245+
? ns.follow_tag(to_struct_tag_type(root.type()))
2246+
: to_struct_type(root.type());
22292247
const struct_typet::componentst &components=
22302248
struct_type.components();
22312249

@@ -2316,7 +2334,7 @@ simplify_exprt::simplify_byte_update(const byte_update_exprt &expr)
23162334
if(root.id()==ID_array)
23172335
{
23182336
auto el_size =
2319-
pointer_offset_bits(to_type_with_subtype(op_type).subtype(), ns);
2337+
pointer_offset_bits(to_type_with_subtype(root.type()).subtype(), ns);
23202338

23212339
if(
23222340
!el_size.has_value() || *el_size == 0 ||

Diff for: src/util/simplify_expr_pointer.cpp

+7-3
Original file line numberDiff line numberDiff line change
@@ -149,18 +149,22 @@ simplify_exprt::simplify_address_of_arg(const exprt &expr)
149149
no_change = false;
150150
}
151151

152-
const typet &op_type = ns.follow(new_member_expr.struct_op().type());
152+
const typet &op_type = new_member_expr.struct_op().type();
153153

154-
if(op_type.id() == ID_struct)
154+
if(op_type.id() == ID_struct || op_type.id() == ID_struct_tag)
155155
{
156156
// rewrite NULL -> member by
157157
// pushing the member inside
158158

159159
mp_integer address;
160160
if(is_dereference_integer_object(new_member_expr.struct_op(), address))
161161
{
162+
const struct_typet &struct_type =
163+
op_type.id() == ID_struct_tag
164+
? ns.follow_tag(to_struct_tag_type(op_type))
165+
: to_struct_type(op_type);
162166
const irep_idt &member = to_member_expr(expr).get_component_name();
163-
auto offset = member_offset(to_struct_type(op_type), member, ns);
167+
auto offset = member_offset(struct_type, member, ns);
164168
if(offset.has_value())
165169
{
166170
pointer_typet pointer_type = to_pointer_type(

0 commit comments

Comments
 (0)