Skip to content

Commit c914c2c

Browse files
authored
Merge pull request #8724 from tautschnig/simplify-with-single-member
Simplify WITH expression over structs with a single component
2 parents 4f59921 + b87c98a commit c914c2c

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
CORE
22
functional.c
33
-DN=4 -DSLICE_BYTES --program-only
4+
WITH \[.*i!0@1#2:=\{ \.coeffs=byte_extract
45
^EXIT=0$
56
^SIGNAL=0$
67
--
78
byte_update
9+
WITH \[.*i!0@1#2:=\{ \{ \.coeffs=\{
810
--
911
We want these tests not to produce any byte_update expressions, but instead want
1012
updates at specific array indices.

src/util/simplify_expr.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1470,14 +1470,14 @@ simplify_exprt::resultt<> simplify_exprt::simplify_with(const with_exprt &expr)
14701470
expr.old().type().id() == ID_struct ||
14711471
expr.old().type().id() == ID_struct_tag)
14721472
{
1473+
const struct_typet &old_type_followed =
1474+
expr.old().type().id() == ID_struct_tag
1475+
? ns.follow_tag(to_struct_tag_type(expr.old().type()))
1476+
: to_struct_type(expr.old().type());
1477+
const irep_idt &component_name = expr.where().get(ID_component_name);
1478+
14731479
if(expr.old().id() == ID_struct || expr.old().is_constant())
14741480
{
1475-
const irep_idt &component_name = expr.where().get(ID_component_name);
1476-
1477-
const struct_typet &old_type_followed =
1478-
expr.old().type().id() == ID_struct_tag
1479-
? ns.follow_tag(to_struct_tag_type(expr.old().type()))
1480-
: to_struct_type(expr.old().type());
14811481
if(!old_type_followed.has_component(component_name))
14821482
return unchanged(expr);
14831483

@@ -1490,6 +1490,12 @@ simplify_exprt::resultt<> simplify_exprt::simplify_with(const with_exprt &expr)
14901490
result.operands()[number] = expr.new_value();
14911491
return result;
14921492
}
1493+
else if(
1494+
old_type_followed.components().size() == 1 &&
1495+
old_type_followed.has_component(component_name))
1496+
{
1497+
return struct_exprt{{expr.new_value()}, expr.type()};
1498+
}
14931499
}
14941500
else if(
14951501
expr.old().type().id() == ID_array || expr.old().type().id() == ID_vector)

0 commit comments

Comments
 (0)