Skip to content

Commit 246da8c

Browse files
author
Daniel Kroening
committed
value_sets now have function identifiers
1 parent 660dfae commit 246da8c

16 files changed

+153
-128
lines changed

src/analyses/flow_insensitive_analysis.cpp

Lines changed: 55 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,6 @@ void flow_insensitive_analysis_baset::operator()(
5656
fixedpoint(goto_functions);
5757
}
5858

59-
void flow_insensitive_analysis_baset::operator()(
60-
const goto_programt &goto_program)
61-
{
62-
initialize(goto_program);
63-
goto_functionst goto_functions;
64-
fixedpoint(goto_program, goto_functions);
65-
}
66-
6759
void flow_insensitive_analysis_baset::output(
6860
const goto_functionst &goto_functions,
6961
std::ostream &out)
@@ -72,14 +64,14 @@ void flow_insensitive_analysis_baset::output(
7264
{
7365
out << "////\n" << "//// Function: " << f_it->first << "\n////\n\n";
7466

75-
output(f_it->second.body, f_it->first, out);
67+
output(f_it->first, f_it->second.body, out);
7668
}
7769
}
7870

7971
void flow_insensitive_analysis_baset::output(
80-
const goto_programt &,
8172
const irep_idt &,
82-
std::ostream &out) const
73+
const goto_programt &,
74+
std::ostream &out)
8375
{
8476
get_state().output(ns, out);
8577
}
@@ -102,6 +94,7 @@ flow_insensitive_analysis_baset::get_next(
10294
}
10395

10496
bool flow_insensitive_analysis_baset::fixedpoint(
97+
const irep_idt &function_identifier,
10598
const goto_programt &goto_program,
10699
const goto_functionst &goto_functions)
107100
{
@@ -122,14 +115,15 @@ bool flow_insensitive_analysis_baset::fixedpoint(
122115
{
123116
locationt l=get_next(working_set);
124117

125-
if(visit(l, working_set, goto_program, goto_functions))
118+
if(visit(function_identifier, l, working_set, goto_program, goto_functions))
126119
new_data=true;
127120
}
128121

129122
return new_data;
130123
}
131124

132125
bool flow_insensitive_analysis_baset::visit(
126+
const irep_idt &function_identifier,
133127
locationt l,
134128
working_sett &working_set,
135129
const goto_programt &goto_program,
@@ -160,16 +154,17 @@ bool flow_insensitive_analysis_baset::visit(
160154
// this is a big special case
161155
const code_function_callt &code = to_code_function_call(l->code);
162156

163-
changed=
164-
do_function_call_rec(
165-
l,
166-
code.function(),
167-
code.arguments(),
168-
get_state(),
169-
goto_functions);
157+
changed = do_function_call_rec(
158+
function_identifier,
159+
l,
160+
code.function(),
161+
code.arguments(),
162+
get_state(),
163+
goto_functions);
170164
}
171165
else
172-
changed = get_state().transform(ns, l, to_l);
166+
changed = get_state().transform(
167+
ns, function_identifier, l, function_identifier, to_l);
173168

174169
if(changed || !seen(to_l))
175170
{
@@ -196,6 +191,7 @@ bool flow_insensitive_analysis_baset::visit(
196191
}
197192

198193
bool flow_insensitive_analysis_baset::do_function_call(
194+
const irep_idt &calling_function,
199195
locationt l_call,
200196
const goto_functionst &goto_functions,
201197
const goto_functionst::function_mapt::const_iterator f_it,
@@ -225,9 +221,11 @@ bool flow_insensitive_analysis_baset::do_function_call(
225221
t->location_number=1;
226222

227223
locationt l_next=l_call; l_next++;
228-
bool new_data=state.transform(ns, l_call, r);
229-
new_data = state.transform(ns, r, t) || new_data;
230-
new_data = state.transform(ns, t, l_next) || new_data;
224+
bool new_data =
225+
state.transform(ns, calling_function, l_call, f_it->first, r);
226+
new_data = state.transform(ns, f_it->first, r, f_it->first, t) || new_data;
227+
new_data =
228+
state.transform(ns, f_it->first, t, calling_function, l_next) || new_data;
231229

232230
return new_data;
233231
}
@@ -244,7 +242,8 @@ bool flow_insensitive_analysis_baset::do_function_call(
244242
l_begin->function == f_it->first, "function names have to match");
245243

246244
// do the edge from the call site to the beginning of the function
247-
new_data=state.transform(ns, l_call, l_begin);
245+
new_data =
246+
state.transform(ns, calling_function, l_call, f_it->first, l_begin);
248247

249248
// do each function at least once
250249
if(functions_done.find(f_it->first)==
@@ -258,7 +257,7 @@ bool flow_insensitive_analysis_baset::do_function_call(
258257
if(new_data)
259258
{
260259
// recursive call
261-
fixedpoint(goto_function.body, goto_functions);
260+
fixedpoint(f_it->first, goto_function.body, goto_functions);
262261
new_data=true; // could be reset by fixedpoint
263262
}
264263
}
@@ -272,13 +271,16 @@ bool flow_insensitive_analysis_baset::do_function_call(
272271
// do edge from end of function to instruction after call
273272
locationt l_next=l_call;
274273
l_next++;
275-
new_data = state.transform(ns, l_end, l_next) || new_data;
274+
new_data =
275+
state.transform(ns, f_it->first, l_end, calling_function, l_next) ||
276+
new_data;
276277
}
277278

278279
return new_data;
279280
}
280281

281282
bool flow_insensitive_analysis_baset::do_function_call_rec(
283+
const irep_idt &calling_function,
282284
locationt l_call,
283285
const exprt &function,
284286
const exprt::operandst &arguments,
@@ -305,13 +307,8 @@ bool flow_insensitive_analysis_baset::do_function_call_rec(
305307
if(it==goto_functions.function_map.end())
306308
throw "failed to find function "+id2string(identifier);
307309

308-
new_data =
309-
do_function_call(
310-
l_call,
311-
goto_functions,
312-
it,
313-
arguments,
314-
state);
310+
new_data = do_function_call(
311+
calling_function, l_call, goto_functions, it, arguments, state);
315312

316313
recursion_set.erase(identifier);
317314
}
@@ -320,21 +317,22 @@ bool flow_insensitive_analysis_baset::do_function_call_rec(
320317
if(function.operands().size()!=3)
321318
throw "if takes three arguments";
322319

323-
new_data =
324-
do_function_call_rec(
325-
l_call,
326-
function.op1(),
327-
arguments,
328-
state,
329-
goto_functions);
330-
331-
new_data =
332-
do_function_call_rec(
333-
l_call,
334-
function.op2(),
335-
arguments,
336-
state,
337-
goto_functions) || new_data;
320+
new_data = do_function_call_rec(
321+
calling_function,
322+
l_call,
323+
function.op1(),
324+
arguments,
325+
state,
326+
goto_functions);
327+
328+
new_data = do_function_call_rec(
329+
calling_function,
330+
l_call,
331+
function.op2(),
332+
arguments,
333+
state,
334+
goto_functions) ||
335+
new_data;
338336
}
339337
else if(function.id()==ID_dereference)
340338
{
@@ -356,13 +354,14 @@ bool flow_insensitive_analysis_baset::do_function_call_rec(
356354

357355
if(it!=goto_functions.function_map.end())
358356
{
359-
new_data =
360-
do_function_call_rec(
361-
l_call,
362-
o.object(),
363-
arguments,
364-
state,
365-
goto_functions) || new_data;
357+
new_data = do_function_call_rec(
358+
calling_function,
359+
l_call,
360+
o.object(),
361+
arguments,
362+
state,
363+
goto_functions) ||
364+
new_data;
366365
}
367366
}
368367
}
@@ -405,7 +404,7 @@ bool flow_insensitive_analysis_baset::fixedpoint(
405404
const goto_functionst &goto_functions)
406405
{
407406
functions_done.insert(it->first);
408-
return fixedpoint(it->second.body, goto_functions);
407+
return fixedpoint(it->first, it->second.body, goto_functions);
409408
}
410409

411410
void flow_insensitive_analysis_baset::update(const goto_functionst &)

src/analyses/flow_insensitive_analysis.h

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,10 @@ class flow_insensitive_abstract_domain_baset
4747

4848
virtual bool transform(
4949
const namespacet &ns,
50+
const irep_idt &function_from,
5051
locationt from,
51-
locationt to)=0;
52+
const irep_idt &function_to,
53+
locationt to) = 0;
5254

5355
virtual ~flow_insensitive_abstract_domain_baset()
5456
{
@@ -146,20 +148,13 @@ class flow_insensitive_analysis_baset
146148
std::ostream &out);
147149

148150
virtual void output(
151+
const irep_idt &function_identifier,
149152
const goto_programt &goto_program,
150-
std::ostream &out)
151-
{
152-
output(goto_program, "", out);
153-
}
153+
std::ostream &out);
154154

155155
protected:
156156
const namespacet &ns;
157157

158-
virtual void output(
159-
const goto_programt &goto_program,
160-
const irep_idt &identifier,
161-
std::ostream &out) const;
162-
163158
typedef std::priority_queue<locationt> working_sett;
164159

165160
locationt get_next(working_sett &working_set);
@@ -173,6 +168,7 @@ class flow_insensitive_analysis_baset
173168

174169
// true = found something new
175170
bool fixedpoint(
171+
const irep_idt &function_identifier,
176172
const goto_programt &goto_program,
177173
const goto_functionst &goto_functions);
178174

@@ -185,6 +181,7 @@ class flow_insensitive_analysis_baset
185181

186182
// true = found something new
187183
bool visit(
184+
const irep_idt &function_identifier,
188185
locationt l,
189186
working_sett &working_set,
190187
const goto_programt &goto_program,
@@ -206,13 +203,15 @@ class flow_insensitive_analysis_baset
206203

207204
// function calls
208205
bool do_function_call_rec(
206+
const irep_idt &calling_function,
209207
locationt l_call,
210208
const exprt &function,
211209
const exprt::operandst &arguments,
212210
statet &new_state,
213211
const goto_functionst &goto_functions);
214212

215213
bool do_function_call(
214+
const irep_idt &calling_function,
216215
locationt l_call,
217216
const goto_functionst &goto_functions,
218217
const goto_functionst::function_mapt::const_iterator f_it,

src/goto-symex/precondition.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ void preconditiont::compute_rec(exprt &dest)
113113
// aliasing may happen here
114114

115115
value_setst::valuest expr_set;
116-
value_sets.get_values(target, deref_expr.pointer(), expr_set);
116+
value_sets.get_values(
117+
SSA_step.source.function, target, deref_expr.pointer(), expr_set);
117118
std::unordered_set<irep_idt> symbols;
118119

119120
for(value_setst::valuest::const_iterator

src/pointer-analysis/goto_program_dereference.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ void goto_program_dereferencet::get_value_set(
228228
const exprt &expr,
229229
value_setst::valuest &dest)
230230
{
231-
value_sets.get_values(current_target, expr, dest);
231+
value_sets.get_values(current_function, current_target, expr, dest);
232232
}
233233

234234
void goto_program_dereferencet::dereference_expr(
@@ -348,9 +348,11 @@ void goto_program_dereferencet::dereference_instruction(
348348
}
349349

350350
void goto_program_dereferencet::dereference_expression(
351+
const irep_idt &function_identifier,
351352
goto_programt::const_targett target,
352353
exprt &expr)
353354
{
355+
current_function = function_identifier;
354356
current_target=target;
355357
#if 0
356358
valid_local_variables=&target->local_variables;
@@ -427,6 +429,7 @@ void pointer_checks(
427429
}
428430

429431
void dereference(
432+
const irep_idt &function_identifier,
430433
goto_programt::const_targett target,
431434
exprt &expr,
432435
const namespacet &ns,
@@ -436,5 +439,6 @@ void dereference(
436439
symbol_tablet new_symbol_table;
437440
goto_program_dereferencet
438441
goto_program_dereference(ns, new_symbol_table, options, value_sets);
439-
goto_program_dereference.dereference_expression(target, expr);
442+
goto_program_dereference.dereference_expression(
443+
function_identifier, target, expr);
440444
}

src/pointer-analysis/goto_program_dereference.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class goto_program_dereferencet:protected dereference_callbackt
5050
void pointer_checks(goto_functionst &goto_functions);
5151

5252
void dereference_expression(
53+
const irep_idt &function,
5354
goto_programt::const_targett target,
5455
exprt &expr);
5556

@@ -92,6 +93,7 @@ class goto_program_dereferencet:protected dereference_callbackt
9293
const std::set<irep_idt> *valid_local_variables;
9394
#endif
9495
source_locationt dereference_location;
96+
irep_idt current_function;
9597
goto_programt::const_targett current_target;
9698

9799
std::set<exprt> assertions;

src/pointer-analysis/value_set_analysis.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class value_set_analysis_templatet:
5959
public:
6060
// interface value_sets
6161
virtual void get_values(
62+
const irep_idt &function_identifier,
6263
locationt l,
6364
const exprt &expr,
6465
value_setst::valuest &dest)

src/pointer-analysis/value_set_analysis_fi.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ class value_set_analysis_fit:
3535

3636
typedef flow_insensitive_analysist<value_set_domain_fit> baset;
3737

38-
virtual void initialize(const goto_programt &goto_program);
39-
virtual void initialize(const goto_functionst &goto_functions);
38+
void initialize(const goto_programt &goto_program) override;
39+
void initialize(const goto_functionst &goto_functions) override;
4040

4141
protected:
4242
track_optionst track_options;
@@ -58,15 +58,16 @@ class value_set_analysis_fit:
5858

5959
public:
6060
// interface value_sets
61-
virtual void get_values(
61+
void get_values(
62+
const irep_idt &function_identifier,
6263
locationt l,
6364
const exprt &expr,
64-
std::list<exprt> &dest)
65+
std::list<exprt> &dest) override
6566
{
6667
state.value_set.from_function =
67-
state.value_set.function_numbering.number(l->function);
68+
state.value_set.function_numbering.number(function_identifier);
6869
state.value_set.to_function =
69-
state.value_set.function_numbering.number(l->function);
70+
state.value_set.function_numbering.number(function_identifier);
7071
state.value_set.from_target_index = l->location_number;
7172
state.value_set.to_target_index = l->location_number;
7273
state.value_set.get_value_set(expr, dest, ns);

0 commit comments

Comments
 (0)