Skip to content

Commit 85bec38

Browse files
author
thk123
committed
Fixing constant propogation test
The variable_sensitivity_domaint::ai_simplify was retuning true if it simplied, but it should have been returning true if no simplification was performed (as specified in ai.h). The test also had the wrong number of goto statements, there are two in the original program, both of which are removed
1 parent 56be172 commit 85bec38

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1+
#include <assert.h>
12

23
int main()
34
{
45
int i, j=20;
5-
6+
67
if (j==20)
78
{
89
int x=1,y=2,z;
910
z=x+y;
1011
assert(z==3);
1112
}
12-
13+
1314
}

regression/goto-analyzer/constant_propagation_01/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ main.c
33
--variable --simplify out.gb
44
^EXIT=0$
55
^SIGNAL=0$
6-
^Simplified: assert: 1, assume: 0, goto: 1, assigns: 5, function calls: 0$
6+
^Simplified: assert: 1, assume: 0, goto: 2, assigns: 5, function calls: 0$
77
^Unmodified: assert: 0, assume: 0, goto: 0, assigns: 12, function calls: 2$
88
--
99
^warning: ignoring

src/analyses/variable-sensitivity/variable_sensitivity_domain.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,7 @@ Function: variable_sensitivity_domaint::ai_simplify
261261
ns - the namespace
262262
lhs - is the expression on the left hand side
263263
264-
Outputs: True if simplified the condition. False otherwise. condition
265-
will be updated with the simplified condition if it has worked
264+
Outputs: True if no simplification was made
266265
267266
Purpose: Use the information in the domain to simplify the expression
268267
with respect to the current location. This may be able to
@@ -282,13 +281,13 @@ bool variable_sensitivity_domaint::ai_simplify(
282281
sharing_ptrt<abstract_objectt> res = abstract_state.eval(condition, ns);
283282
exprt c = res->to_constant();
284283

285-
if (c.id() == ID_nil) // TODO : simplification within an expression
286-
return false;
284+
if(c.id() == ID_nil) // TODO : simplification within an expression
285+
return true;
287286
else
288287
{
289-
bool b = (condition!=c);
288+
bool condition_changed = (condition!=c);
290289
condition = c;
291-
return b;
290+
return !condition_changed;
292291
}
293292
}
294293
assert(0); // All conditions should be handled
@@ -335,7 +334,7 @@ Function: variable_sensitivity_domaint::ai_simplify_lhs
335334
condition - the expression to simplify
336335
ns - the namespace
337336
338-
Outputs: True if simplified the condition. False otherwise. condition
337+
Outputs: True if condition did not change. False otherwise. condition
339338
will be updated with the simplified condition if it has worked
340339
341340
Purpose: Use the information in the domain to simplify the expression
@@ -360,7 +359,7 @@ bool variable_sensitivity_domaint::ai_simplify_lhs(
360359
condition = simplify_expr(ie, ns);
361360
}
362361

363-
return changed;
362+
return !changed;
364363
}
365364
else if (condition.id()==ID_dereference)
366365
{
@@ -373,7 +372,7 @@ bool variable_sensitivity_domaint::ai_simplify_lhs(
373372
condition = simplify_expr(de, ns); // So *(&x) -> x
374373
}
375374

376-
return changed;
375+
return !changed;
377376
}
378377
else if (condition.id()==ID_member)
379378
{
@@ -386,8 +385,8 @@ bool variable_sensitivity_domaint::ai_simplify_lhs(
386385
condition = simplify_expr(me, ns);
387386
}
388387

389-
return changed;
388+
return !changed;
390389
}
391390
else
392-
return false;
391+
return true;
393392
}

0 commit comments

Comments
 (0)