Skip to content

Commit 51fcd8c

Browse files
committed
Do not sort operands as part of simplification
1 parent 18da0b1 commit 51fcd8c

File tree

5 files changed

+16
-13
lines changed

5 files changed

+16
-13
lines changed

jbmc/regression/jbmc/throwing-function-return-value/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ CORE
22
Test.class
33
--function Test.main --show-vcc
44
java::Test\.main:\(Z\)V::14::t1!0@1#\d+ = address_of\(symex_dynamic::dynamic_object\d+\)
5-
java::Test\.main:\(Z\)V::9::x!0@1#\d+ = 5 \+ java::Test\.main:\(Z\)V::9::x!0@1#\d+
5+
java::Test\.main:\(Z\)V::9::x!0@1#\d+ = java::Test\.main:\(Z\)V::9::x!0@1#\d+ \+ 5
66
java::Test\.g:\(\)I#return_value!0#[0-9]+ = 5
77
^EXIT=0$
88
^SIGNAL=0$

regression/goto-analyzer/constant_propagation_07/test.desc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ main.c
33
--constants --simplify out.gb
44
^EXIT=0$
55
^SIGNAL=0$
6-
^Simplified: assert: 1, assume: 0, goto: 3, assigns: 11, function calls: 0$
7-
^Unmodified: assert: 0, assume: 0, goto: 1, assigns: 10, function calls: 2$
6+
^Simplified: assert: 1, assume: 0, goto: 3, assigns: 7, function calls: 0$
7+
^Unmodified: assert: 0, assume: 0, goto: 1, assigns: 14, function calls: 2$
88
--
99
^warning: ignoring

src/util/simplify_expr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2375,7 +2375,7 @@ bool simplify_exprt::simplify_node(exprt &expr)
23752375

23762376
bool result=true;
23772377

2378-
result=sort_and_join(expr) && result;
2378+
result = sort_and_join(expr, false) && result;
23792379

23802380
if(expr.id()==ID_typecast)
23812381
result=simplify_typecast(expr) && result;

src/util/simplify_utils.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,30 +119,31 @@ static const struct saj_tablet &sort_and_join(
119119
return saj_table[i];
120120
}
121121

122-
bool sort_and_join(exprt &expr)
122+
bool sort_and_join(exprt &expr, bool do_sort)
123123
{
124124
bool result=true;
125125

126126
if(!expr.has_operands())
127127
return true;
128128

129-
const struct saj_tablet &saj_entry=
130-
sort_and_join(expr.id(), expr.type().id());
129+
const exprt &expr_const = expr;
130+
const struct saj_tablet &saj_entry =
131+
sort_and_join(expr_const.id(), expr_const.type().id());
131132
if(saj_entry.id.empty())
132133
return true;
133134

134135
// check operand types
135136

136-
forall_operands(it, expr)
137+
forall_operands(it, expr_const)
137138
if(!sort_and_join(saj_entry, it->type().id()))
138139
return true;
139140

140141
// join expressions
141142

142143
exprt::operandst new_ops;
143-
new_ops.reserve(expr.operands().size());
144+
new_ops.reserve(expr_const.operands().size());
144145

145-
forall_operands(it, expr)
146+
forall_operands(it, expr_const)
146147
{
147148
if(it->id()==expr.id())
148149
{
@@ -158,9 +159,11 @@ bool sort_and_join(exprt &expr)
158159
}
159160

160161
// sort it
162+
if(do_sort)
163+
result = sort_operands(new_ops) && result;
161164

162-
result=sort_operands(new_ops) && result;
163-
expr.operands().swap(new_ops);
165+
if(!result)
166+
expr.operands().swap(new_ops);
164167

165168
return result;
166169
}

src/util/simplify_utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ Author: Daniel Kroening, kroening@kroening.com
1414

1515
bool sort_operands(exprt::operandst &operands);
1616

17-
bool sort_and_join(exprt &expr);
17+
bool sort_and_join(exprt &expr, bool do_sort = true);
1818

1919
#endif // CPROVER_UTIL_SIMPLIFY_UTILS_H

0 commit comments

Comments
 (0)