Skip to content

Commit 273d23e

Browse files
author
martin
committed
Add an extra argument to domain_simplify so that the left hand side of assignment operations is treated differently.
1 parent 1fa7691 commit 273d23e

File tree

6 files changed

+32
-11
lines changed

6 files changed

+32
-11
lines changed

src/analyses/ai.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ class ai_domain_baset
103103

104104
// Used to evaluate or simplify conditions with respect to the domain
105105
virtual exprt domain_simplify (const exprt &condition,
106-
const namespacet &ns) const {
106+
const namespacet &ns,
107+
const bool lhs = false) const {
107108
return condition;
108109
}
109110
};

src/analyses/constant_propagator.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ void constant_propagator_domaint::assign(
334334

335335
/*******************************************************************\
336336
337-
Function: constant_propagator_domaint::assign
337+
Function: constant_propagator_domaint::domain_simplify
338338
339339
Inputs: The condition to simplify and its namespace.
340340
@@ -345,11 +345,17 @@ Function: constant_propagator_domaint::assign
345345
\*******************************************************************/
346346

347347
exprt constant_propagator_domaint::domain_simplify (const exprt &condition,
348-
const namespacet &ns)
348+
const namespacet &ns,
349+
const bool lhs)
349350
{
350-
exprt e(condition);
351-
values.replace_const(e);
352-
return simplify_expr(e, ns);
351+
if (lhs) {
352+
// For now do not simplify the left hand sides of assignments
353+
return condition;
354+
} else {
355+
exprt e(condition);
356+
values.replace_const(e);
357+
return simplify_expr(e, ns);
358+
}
353359
}
354360

355361
/*******************************************************************\

src/analyses/constant_propagator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class constant_propagator_domaint:public ai_domain_baset
1919
virtual void transform(locationt, locationt, ai_baset &, const namespacet &);
2020
virtual void output(std::ostream &, const ai_baset &, const namespacet &) const;
2121
bool merge(const constant_propagator_domaint &, locationt, locationt);
22-
virtual exprt domain_simplify (const exprt &condition, const namespacet &ns);
22+
virtual exprt domain_simplify (const exprt &condition, const namespacet &ns, const bool lhs = false);
2323

2424
struct valuest
2525
{

src/analyses/interval_domain.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,8 +514,14 @@ Function: interval_domaint::domain_simplify
514514
\*******************************************************************/
515515

516516
exprt interval_domaint::domain_simplify (const exprt &condition,
517-
const namespacet &ns) const
517+
const namespacet &ns,
518+
const bool lhs) const
518519
{
520+
if (lhs) {
521+
// For now do not simplify the left hand side of assignments
522+
return condition;
523+
}
524+
519525
interval_domaint d(*this);
520526

521527
//merge intervals to properly handle conjunction

src/analyses/interval_domain.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ class interval_domaint:public ai_domain_baset
8282
}
8383

8484
virtual exprt domain_simplify (const exprt &condition,
85-
const namespacet &ns) const;
85+
const namespacet &ns,
86+
const bool lhs = false) const;
8687

8788
protected:
8889
bool bottom;

src/goto-analyzer/static_simplifier.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,16 @@ void static_simplifiert<analyzerT>::simplify_program()
151151
else if (i_it->is_assign())
152152
{
153153
code_assignt assign(to_code_assign(i_it->code));
154+
155+
/*
156+
** Simplification needs to be aware of which side of the
157+
** expression it is handling as:
158+
** <i = 0, j = 1> i = j
159+
** should simplify to i = 1, not to 0 = 1.
160+
*/
154161

155-
exprt simplified_lhs = domain[i_it].domain_simplify(assign.lhs(), ns);
156-
exprt simplified_rhs = domain[i_it].domain_simplify(assign.rhs(), ns);
162+
exprt simplified_lhs = domain[i_it].domain_simplify(assign.lhs(), ns, true);
163+
exprt simplified_rhs = domain[i_it].domain_simplify(assign.rhs(), ns, false);
157164

158165
unsigned result = (simplified_lhs == assign.lhs() &&
159166
simplified_rhs == assign.rhs()) ? 0 : 1;

0 commit comments

Comments
 (0)