Skip to content

Commit 250f5af

Browse files
authored
Merge pull request #3806 from tautschnig/bits2expr
bits2expr must return an expression of the requested type [blocks: #3652]
2 parents 9129e09 + 26786cb commit 250f5af

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

src/util/simplify_expr.cpp

Lines changed: 22 additions & 9 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,16 @@ 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(
1470-
bits,
1471-
ns.follow_tag(to_c_enum_tag_type(type)),
1472-
little_endian);
1466+
{
1467+
exprt val =
1468+
bits2expr(bits, ns.follow_tag(to_c_enum_tag_type(type)), little_endian);
1469+
val.type() = type;
1470+
return val;
1471+
}
14731472
else if(type.id()==ID_union)
14741473
{
14751474
// find a suitable member
@@ -1486,6 +1485,13 @@ exprt simplify_exprt::bits2expr(
14861485
return union_exprt(component.get_name(), val, type);
14871486
}
14881487
}
1488+
else if(type.id() == ID_union_tag)
1489+
{
1490+
exprt val =
1491+
bits2expr(bits, ns.follow_tag(to_union_tag_type(type)), little_endian);
1492+
val.type() = type;
1493+
return val;
1494+
}
14891495
else if(type.id()==ID_struct)
14901496
{
14911497
const struct_typet &struct_type=to_struct_type(type);
@@ -1516,6 +1522,13 @@ exprt simplify_exprt::bits2expr(
15161522

15171523
return std::move(result);
15181524
}
1525+
else if(type.id() == ID_struct_tag)
1526+
{
1527+
exprt val =
1528+
bits2expr(bits, ns.follow_tag(to_struct_tag_type(type)), little_endian);
1529+
val.type() = type;
1530+
return val;
1531+
}
15191532
else if(type.id()==ID_array)
15201533
{
15211534
const array_typet &array_type=to_array_type(type);

0 commit comments

Comments
 (0)