Skip to content

Commit d08c44a

Browse files
committed
Apply adjust_float_expressions, rewrite_union just once per expression
These should be applied once across all goto functions instead of possibly applying them multiple times to the same source expression during symbolic execution. Signed-off-by: Michael Tautschnig <[email protected]>
1 parent a77377e commit d08c44a

8 files changed

+171
-24
lines changed

src/cbmc/cbmc_parse_options.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ Author: Daniel Kroening, [email protected]
3939
#include <goto-programs/remove_skip.h>
4040
#include <goto-programs/show_goto_functions.h>
4141

42+
#include <goto-symex/rewrite_union.h>
43+
#include <goto-symex/adjust_float_expressions.h>
44+
4245
#include <goto-instrument/full_slicer.h>
4346
#include <goto-instrument/nondet_static.h>
4447
#include <goto-instrument/cover.h>
@@ -891,10 +894,13 @@ bool cbmc_parse_optionst::process_goto_program(
891894
remove_returns(symbol_table, goto_functions);
892895
remove_vector(symbol_table, goto_functions);
893896
remove_complex(symbol_table, goto_functions);
897+
rewrite_union(goto_functions, ns);
894898

895899
// add generic checks
896900
status() << "Generic Property Instrumentation" << eom;
897901
goto_check(ns, options, goto_functions);
902+
// checks don't know about adjusted float expressions
903+
adjust_float_expressions(goto_functions, ns);
898904

899905
// ignore default/user-specified initialization
900906
// of variables with static lifetime

src/goto-symex/adjust_float_expressions.cpp

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Author: Daniel Kroening, [email protected]
1313
#include <util/ieee_float.h>
1414
#include <util/arith_tools.h>
1515

16+
#include <goto-programs/goto_model.h>
17+
1618
#include "adjust_float_expressions.h"
1719

1820
/*******************************************************************\
@@ -32,6 +34,15 @@ void adjust_float_expressions(
3234
exprt &expr,
3335
const namespacet &ns)
3436
{
37+
if(expr.id()==ID_floatbv_plus ||
38+
expr.id()==ID_floatbv_minus ||
39+
expr.id()==ID_floatbv_mult ||
40+
expr.id()==ID_floatbv_div ||
41+
expr.id()==ID_floatbv_div ||
42+
expr.id()==ID_floatbv_rem ||
43+
expr.id()==ID_floatbv_typecast)
44+
return;
45+
3546
Forall_operands(it, expr)
3647
adjust_float_expressions(*it, ns);
3748

@@ -126,3 +137,64 @@ void adjust_float_expressions(
126137
}
127138
}
128139
}
140+
141+
/*******************************************************************\
142+
143+
Function: adjust_float_expressions
144+
145+
Inputs:
146+
147+
Outputs:
148+
149+
Purpose:
150+
151+
\*******************************************************************/
152+
153+
static void adjust_float_expressions(
154+
goto_functionst::goto_functiont &goto_function,
155+
const namespacet &ns)
156+
{
157+
Forall_goto_program_instructions(it, goto_function.body)
158+
{
159+
adjust_float_expressions(it->code, ns);
160+
adjust_float_expressions(it->guard, ns);
161+
}
162+
}
163+
164+
/*******************************************************************\
165+
166+
Function: adjust_float_expressions
167+
168+
Inputs:
169+
170+
Outputs:
171+
172+
Purpose:
173+
174+
\*******************************************************************/
175+
176+
void adjust_float_expressions(
177+
goto_functionst &goto_functions,
178+
const namespacet &ns)
179+
{
180+
Forall_goto_functions(it, goto_functions)
181+
adjust_float_expressions(it->second, ns);
182+
}
183+
184+
/*******************************************************************\
185+
186+
Function: adjust_float_expressions
187+
188+
Inputs:
189+
190+
Outputs:
191+
192+
Purpose:
193+
194+
\*******************************************************************/
195+
196+
void adjust_float_expressions(goto_modelt &goto_model)
197+
{
198+
namespacet ns(goto_model.symbol_table);
199+
adjust_float_expressions(goto_model.goto_functions, ns);
200+
}

src/goto-symex/adjust_float_expressions.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,18 @@ Author: Daniel Kroening, [email protected]
99
#ifndef CPROVER_GOTO_SYMEX_ADJUST_FLOAT_EXPRESSIONS_H
1010
#define CPROVER_GOTO_SYMEX_ADJUST_FLOAT_EXPRESSIONS_H
1111

12-
#include <util/expr.h>
13-
#include <util/namespace.h>
12+
class exprt;
13+
class namespacet;
14+
class goto_functionst;
15+
class goto_modelt;
1416

1517
void adjust_float_expressions(
1618
exprt &expr,
1719
const namespacet &ns);
1820

21+
void adjust_float_expressions(
22+
goto_functionst &goto_functions,
23+
const namespacet &ns);
24+
void adjust_float_expressions(goto_modelt &goto_model);
25+
1926
#endif // CPROVER_GOTO_SYMEX_ADJUST_FLOAT_EXPRESSIONS_H

src/goto-symex/rewrite_union.cpp

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ Author: Daniel Kroening, [email protected]
1111
#include <util/expr_util.h>
1212
#include <util/byte_operators.h>
1313

14+
#include <goto-programs/goto_model.h>
15+
1416
#include <ansi-c/c_types.h>
1517

1618
#include "rewrite_union.h"
@@ -57,3 +59,64 @@ void rewrite_union(
5759
expr=tmp;
5860
}
5961
}
62+
63+
/*******************************************************************\
64+
65+
Function: rewrite_union
66+
67+
Inputs:
68+
69+
Outputs:
70+
71+
Purpose:
72+
73+
\*******************************************************************/
74+
75+
static void rewrite_union(
76+
goto_functionst::goto_functiont &goto_function,
77+
const namespacet &ns)
78+
{
79+
Forall_goto_program_instructions(it, goto_function.body)
80+
{
81+
rewrite_union(it->code, ns);
82+
rewrite_union(it->guard, ns);
83+
}
84+
}
85+
86+
/*******************************************************************\
87+
88+
Function: rewrite_union
89+
90+
Inputs:
91+
92+
Outputs:
93+
94+
Purpose:
95+
96+
\*******************************************************************/
97+
98+
void rewrite_union(
99+
goto_functionst &goto_functions,
100+
const namespacet &ns)
101+
{
102+
Forall_goto_functions(it, goto_functions)
103+
rewrite_union(it->second, ns);
104+
}
105+
106+
/*******************************************************************\
107+
108+
Function: rewrite_union
109+
110+
Inputs:
111+
112+
Outputs:
113+
114+
Purpose:
115+
116+
\*******************************************************************/
117+
118+
void rewrite_union(goto_modelt &goto_model)
119+
{
120+
namespacet ns(goto_model.symbol_table);
121+
rewrite_union(goto_model.goto_functions, ns);
122+
}

src/goto-symex/rewrite_union.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,20 @@ Author: Daniel Kroening, [email protected]
99
#ifndef CPROVER_GOTO_SYMEX_REWRITE_UNION_H
1010
#define CPROVER_GOTO_SYMEX_REWRITE_UNION_H
1111

12-
#include <util/expr.h>
13-
#include <util/namespace.h>
12+
#include <goto-programs/goto_functions.h>
13+
14+
class exprt;
15+
class namespacet;
16+
class goto_functionst;
17+
class goto_modelt;
1418

1519
void rewrite_union(
1620
exprt &expr,
1721
const namespacet &ns);
1822

23+
void rewrite_union(
24+
goto_functionst &goto_functions,
25+
const namespacet &ns);
26+
void rewrite_union(goto_modelt &goto_model);
27+
1928
#endif // CPROVER_GOTO_SYMEX_REWRITE_UNION_H

src/goto-symex/symex_clean_expr.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ Author: Daniel Kroening, [email protected]
1313

1414
#include <ansi-c/c_types.h>
1515

16-
#include "adjust_float_expressions.h"
17-
#include "rewrite_union.h"
1816
#include "goto_symex.h"
1917

2018
/*******************************************************************\
@@ -199,9 +197,7 @@ void goto_symext::clean_expr(
199197
statet &state,
200198
const bool write)
201199
{
202-
rewrite_union(expr, ns);
203200
replace_nondet(expr);
204201
dereference(expr, state, write);
205202
replace_array_equal(expr);
206-
adjust_float_expressions(expr, ns);
207203
}

src/path-symex/path_symex_state_read.cpp

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ Author: Daniel Kroening, [email protected]
1111

1212
#include <pointer-analysis/dereference.h>
1313

14-
#include <goto-symex/adjust_float_expressions.h>
15-
#include <goto-symex/rewrite_union.h>
16-
1714
#include "path_symex_state.h"
1815

1916
//#define DEBUG
@@ -41,21 +38,13 @@ exprt path_symex_statet::read(const exprt &src, bool propagate)
4138
//std::cout << "path_symex_statet::read " << src.pretty() << std::endl;
4239
#endif
4340

44-
// This has five phases!
45-
// 1. Floating-point expression adjustment (rounding mode)
46-
// 2. Rewrite unions into byte operators
47-
// 3. Dereferencing, including propagation of pointers.
48-
// 4. Rewriting to SSA symbols
49-
// 5. Simplifier
50-
51-
exprt tmp1=src;
52-
adjust_float_expressions(tmp1, var_map.ns);
53-
54-
exprt tmp2=tmp1;
55-
rewrite_union(tmp2, var_map.ns);
41+
// This has three phases!
42+
// 1. Dereferencing, including propagation of pointers.
43+
// 2. Rewriting to SSA symbols
44+
// 3. Simplifier
5645

5746
// we force propagation for dereferencing
58-
exprt tmp3=dereference_rec(tmp2, true);
47+
exprt tmp3=dereference_rec(src, true);
5948

6049
exprt tmp4=instantiate_rec(tmp3, propagate);
6150

src/symex/symex_parse_options.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ Author: Daniel Kroening, [email protected]
3333
#include <goto-programs/remove_vector.h>
3434
#include <goto-programs/remove_virtual_functions.h>
3535

36+
#include <goto-symex/rewrite_union.h>
37+
#include <goto-symex/adjust_float_expressions.h>
38+
3639
#include <goto-instrument/cover.h>
3740

3841
#include <langapi/mode.h>
@@ -359,6 +362,8 @@ bool symex_parse_optionst::process_goto_program(const optionst &options)
359362
remove_complex(goto_model);
360363
remove_vector(goto_model);
361364
remove_virtual_functions(goto_model);
365+
rewrite_union(goto_model);
366+
adjust_float_expressions(goto_model);
362367

363368
// recalculate numbers, etc.
364369
goto_model.goto_functions.update();

0 commit comments

Comments
 (0)