Skip to content

Commit b614c03

Browse files
committed
bits2expr must return an expression of the requested type
Do not return the expanded version of the type.
1 parent 932b7f5 commit b614c03

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

src/util/simplify_expr.cpp

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,12 +1431,10 @@ bool simplify_exprt::simplify_object(exprt &expr)
14311431

14321432
exprt simplify_exprt::bits2expr(
14331433
const std::string &bits,
1434-
const typet &_type,
1434+
const typet &type,
14351435
bool little_endian)
14361436
{
14371437
// bits start at lowest memory address
1438-
const typet &type=ns.follow(_type);
1439-
14401438
auto type_bits = pointer_offset_bits(type, ns);
14411439

14421440
if(!type_bits.has_value() || *type_bits != bits.size())
@@ -1461,15 +1459,18 @@ exprt simplify_exprt::bits2expr(
14611459
else if(type.id()==ID_c_enum)
14621460
{
14631461
exprt val = bits2expr(bits, to_c_enum_type(type).subtype(), little_endian);
1464-
val.type()=type;
1462+
val.type() = type;
14651463
return val;
14661464
}
14671465
else if(type.id()==ID_c_enum_tag)
1468-
return
1469-
bits2expr(
1466+
{
1467+
exprt val = bits2expr(
14701468
bits,
14711469
ns.follow_tag(to_c_enum_tag_type(type)),
14721470
little_endian);
1471+
val.type() = type;
1472+
return val;
1473+
}
14731474
else if(type.id()==ID_union)
14741475
{
14751476
// find a suitable member
@@ -1486,6 +1487,15 @@ exprt simplify_exprt::bits2expr(
14861487
return union_exprt(component.get_name(), val, type);
14871488
}
14881489
}
1490+
else if(type.id()==ID_union_tag)
1491+
{
1492+
exprt val = bits2expr(
1493+
bits,
1494+
ns.follow_tag(to_union_tag_type(type)),
1495+
little_endian);
1496+
val.type() = type;
1497+
return val;
1498+
}
14891499
else if(type.id()==ID_struct)
14901500
{
14911501
const struct_typet &struct_type=to_struct_type(type);
@@ -1516,6 +1526,15 @@ exprt simplify_exprt::bits2expr(
15161526

15171527
return std::move(result);
15181528
}
1529+
else if(type.id()==ID_struct_tag)
1530+
{
1531+
exprt val = bits2expr(
1532+
bits,
1533+
ns.follow_tag(to_struct_tag_type(type)),
1534+
little_endian);
1535+
val.type() = type;
1536+
return val;
1537+
}
15191538
else if(type.id()==ID_array)
15201539
{
15211540
const array_typet &array_type=to_array_type(type);

0 commit comments

Comments
 (0)