@@ -1449,11 +1449,11 @@ simplify_exprt::resultt<> simplify_exprt::simplify_with(const with_exprt &expr)
1449
1449
// copy
1450
1450
auto with_expr = expr;
1451
1451
1452
- const typet old_type_followed = ns.follow (with_expr.old ().type ());
1453
-
1454
1452
// now look at first operand
1455
1453
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)
1457
1457
{
1458
1458
if (with_expr.old ().id () == ID_struct || with_expr.old ().is_constant ())
1459
1459
{
@@ -1462,11 +1462,14 @@ simplify_exprt::resultt<> simplify_exprt::simplify_with(const with_exprt &expr)
1462
1462
const irep_idt &component_name =
1463
1463
with_expr.where ().get (ID_component_name);
1464
1464
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))
1466
1470
return unchanged (expr);
1467
1471
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);
1470
1473
1471
1474
if (number >= with_expr.old ().operands ().size ())
1472
1475
return unchanged (expr);
@@ -1530,8 +1533,6 @@ simplify_exprt::simplify_update(const update_exprt &expr)
1530
1533
1531
1534
for (const auto &e : designator)
1532
1535
{
1533
- const typet &value_ptr_type=ns.follow (value_ptr->type ());
1534
-
1535
1536
if (e.id ()==ID_index_designator &&
1536
1537
value_ptr->id ()==ID_array)
1537
1538
{
@@ -1551,7 +1552,9 @@ simplify_exprt::simplify_update(const update_exprt &expr)
1551
1552
const irep_idt &component_name=
1552
1553
e.get (ID_component_name);
1553
1554
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 ());
1555
1558
if (!value_ptr_struct_type.has_component (component_name))
1556
1559
return unchanged (expr);
1557
1560
auto &designator_as_struct_expr = to_struct_expr (*value_ptr);
@@ -1788,14 +1791,18 @@ simplify_exprt::simplify_byte_extract(const byte_extract_exprt &expr)
1788
1791
}
1789
1792
1790
1793
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 ()))
1793
1798
{
1794
1799
return empty_union_exprt{expr.type ()};
1795
1800
}
1796
1801
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 ()))
1799
1806
{
1800
1807
return struct_exprt{{}, expr.type ()};
1801
1808
}
@@ -1870,7 +1877,9 @@ simplify_exprt::simplify_byte_extract(const byte_extract_exprt &expr)
1870
1877
if (type.id () != ID_struct && type.id () != ID_struct_tag)
1871
1878
return false ;
1872
1879
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);
1874
1883
const auto &comps = st.components ();
1875
1884
if (comps.empty () || comps.back ().type ().id () != ID_array)
1876
1885
return false ;
@@ -1905,7 +1914,10 @@ simplify_exprt::simplify_byte_extract(const byte_extract_exprt &expr)
1905
1914
{
1906
1915
if (expr.type ().id () == ID_struct || expr.type ().id () == ID_struct_tag)
1907
1916
{
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 ());
1909
1921
const struct_typet::componentst &components = struct_type.components ();
1910
1922
1911
1923
bool failed = false ;
@@ -1950,7 +1962,10 @@ simplify_exprt::simplify_byte_extract(const byte_extract_exprt &expr)
1950
1962
}
1951
1963
else if (expr.type ().id () == ID_union || expr.type ().id () == ID_union_tag)
1952
1964
{
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 ());
1954
1969
auto widest_member_opt = union_type.find_widest_union_component (ns);
1955
1970
if (widest_member_opt.has_value ())
1956
1971
{
@@ -2150,10 +2165,12 @@ simplify_exprt::simplify_byte_update(const byte_update_exprt &expr)
2150
2165
if (!(offset==extract.offset ()))
2151
2166
return unchanged (expr);
2152
2167
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)
2155
2169
{
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 ());
2157
2174
const irep_idt &component_name=with.where ().get (ID_component_name);
2158
2175
const typet &c_type = struct_type.get_component (component_name).type ();
2159
2176
@@ -2178,9 +2195,10 @@ simplify_exprt::simplify_byte_update(const byte_update_exprt &expr)
2178
2195
}
2179
2196
}
2180
2197
}
2181
- else if (tp. id ()== ID_array)
2198
+ else if (with. type (). id () == ID_array)
2182
2199
{
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);
2184
2202
if (i.has_value ())
2185
2203
{
2186
2204
const exprt &index =with.where ();
@@ -2209,23 +2227,23 @@ simplify_exprt::simplify_byte_update(const byte_update_exprt &expr)
2209
2227
if (!offset_int.has_value () || *offset_int < 0 )
2210
2228
return unchanged (expr);
2211
2229
2212
- const typet &op_type=ns.follow (root.type ());
2213
-
2214
2230
// size must be known
2215
2231
if (!val_size.has_value () || *val_size == 0 )
2216
2232
return unchanged (expr);
2217
2233
2218
2234
// Are we updating (parts of) a struct? Do individual member updates
2219
2235
// 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 )
2221
2237
{
2222
2238
exprt result_expr;
2223
2239
result_expr.make_nil ();
2224
2240
2225
2241
auto update_size = pointer_offset_size (value.type (), ns);
2226
2242
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 ());
2229
2247
const struct_typet::componentst &components=
2230
2248
struct_type.components ();
2231
2249
@@ -2316,7 +2334,7 @@ simplify_exprt::simplify_byte_update(const byte_update_exprt &expr)
2316
2334
if (root.id ()==ID_array)
2317
2335
{
2318
2336
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);
2320
2338
2321
2339
if (
2322
2340
!el_size.has_value () || *el_size == 0 ||
0 commit comments