Skip to content

Commit be53e82

Browse files
author
Daniel Kroening
authored
Merge pull request #3130 from diffblue/static-analysis-function
static_analysist now passes function identifiers to transform()
2 parents 49230ec + d8bb574 commit be53e82

File tree

4 files changed

+83
-26
lines changed

4 files changed

+83
-26
lines changed

src/analyses/static_analysis.cpp

Lines changed: 66 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,12 @@ void static_analysis_baset::operator()(
6666
}
6767

6868
void static_analysis_baset::operator()(
69+
const irep_idt &function_identifier,
6970
const goto_programt &goto_program)
7071
{
7172
initialize(goto_program);
7273
goto_functionst goto_functions;
73-
fixedpoint(goto_program, goto_functions);
74+
fixedpoint(function_identifier, goto_program, goto_functions);
7475
}
7576

7677
void static_analysis_baset::output(
@@ -166,6 +167,7 @@ static_analysis_baset::locationt static_analysis_baset::get_next(
166167
}
167168

168169
bool static_analysis_baset::fixedpoint(
170+
const irep_idt &function_identifier,
169171
const goto_programt &goto_program,
170172
const goto_functionst &goto_functions)
171173
{
@@ -184,14 +186,15 @@ bool static_analysis_baset::fixedpoint(
184186
{
185187
locationt l=get_next(working_set);
186188

187-
if(visit(l, working_set, goto_program, goto_functions))
189+
if(visit(function_identifier, l, working_set, goto_program, goto_functions))
188190
new_data=true;
189191
}
190192

191193
return new_data;
192194
}
193195

194196
bool static_analysis_baset::visit(
197+
const irep_idt &function_identifier,
195198
locationt l,
196199
working_sett &working_set,
197200
const goto_programt &goto_program,
@@ -220,14 +223,17 @@ bool static_analysis_baset::visit(
220223
to_code_function_call(l->code);
221224

222225
do_function_call_rec(
223-
l, to_l,
226+
function_identifier,
227+
l,
228+
to_l,
224229
code.function(),
225230
code.arguments(),
226231
new_values,
227232
goto_functions);
228233
}
229234
else
230-
new_values.transform(ns, l, to_l);
235+
new_values.transform(
236+
ns, function_identifier, l, function_identifier, to_l);
231237

232238
statet &other=get_state(to_l);
233239

@@ -245,7 +251,9 @@ bool static_analysis_baset::visit(
245251
}
246252

247253
void static_analysis_baset::do_function_call(
248-
locationt l_call, locationt l_return,
254+
const irep_idt &calling_function,
255+
locationt l_call,
256+
locationt l_return,
249257
const goto_functionst &goto_functions,
250258
const goto_functionst::function_mapt::const_iterator f_it,
251259
const exprt::operandst &,
@@ -264,7 +272,7 @@ void static_analysis_baset::do_function_call(
264272

265273
// do the edge from the call site to the beginning of the function
266274
std::unique_ptr<statet> tmp_state(make_temporary_state(new_state));
267-
tmp_state->transform(ns, l_call, l_begin);
275+
tmp_state->transform(ns, calling_function, l_call, f_it->first, l_begin);
268276

269277
statet &begin_state=get_state(l_begin);
270278

@@ -286,7 +294,7 @@ void static_analysis_baset::do_function_call(
286294
if(new_data)
287295
{
288296
// recursive call
289-
fixedpoint(goto_function.body, goto_functions);
297+
fixedpoint(f_it->first, goto_function.body, goto_functions);
290298
}
291299
}
292300

@@ -301,7 +309,7 @@ void static_analysis_baset::do_function_call(
301309
// do edge from end of function to instruction after call
302310
std::unique_ptr<statet> tmp_state(
303311
make_temporary_state(end_of_function));
304-
tmp_state->transform(ns, l_end, l_return);
312+
tmp_state->transform(ns, f_it->first, l_end, calling_function, l_return);
305313

306314
// propagate those -- not exceedingly precise, this is,
307315
// as still it contains all the state from the
@@ -311,12 +319,15 @@ void static_analysis_baset::do_function_call(
311319

312320
{
313321
// effect on current procedure (if any)
314-
new_state.transform(ns, l_call, l_return);
322+
new_state.transform(
323+
ns, calling_function, l_call, calling_function, l_return);
315324
}
316325
}
317326

318327
void static_analysis_baset::do_function_call_rec(
319-
locationt l_call, locationt l_return,
328+
const irep_idt &calling_function,
329+
locationt l_call,
330+
locationt l_return,
320331
const exprt &function,
321332
const exprt::operandst &arguments,
322333
statet &new_state,
@@ -345,7 +356,9 @@ void static_analysis_baset::do_function_call_rec(
345356
throw "failed to find function "+id2string(identifier);
346357

347358
do_function_call(
348-
l_call, l_return,
359+
calling_function,
360+
l_call,
361+
l_return,
349362
goto_functions,
350363
it,
351364
arguments,
@@ -361,14 +374,18 @@ void static_analysis_baset::do_function_call_rec(
361374
std::unique_ptr<statet> n2(make_temporary_state(new_state));
362375

363376
do_function_call_rec(
364-
l_call, l_return,
377+
calling_function,
378+
l_call,
379+
l_return,
365380
function.op1(),
366381
arguments,
367382
new_state,
368383
goto_functions);
369384

370385
do_function_call_rec(
371-
l_call, l_return,
386+
calling_function,
387+
l_call,
388+
l_return,
372389
function.op2(),
373390
arguments,
374391
*n2,
@@ -392,7 +409,13 @@ void static_analysis_baset::do_function_call_rec(
392409
const object_descriptor_exprt &o=to_object_descriptor_expr(value);
393410
std::unique_ptr<statet> n2(make_temporary_state(new_state));
394411
do_function_call_rec(
395-
l_call, l_return, o.object(), arguments, *n2, goto_functions);
412+
calling_function,
413+
l_call,
414+
l_return,
415+
o.object(),
416+
arguments,
417+
*n2,
418+
goto_functions);
396419
merge(new_state, *n2, l_return);
397420
}
398421
}
@@ -424,7 +447,7 @@ void static_analysis_baset::sequential_fixedpoint(
424447

425448
forall_goto_functions(it, goto_functions)
426449
if(functions_done.insert(it->first).second)
427-
fixedpoint(it->second.body, goto_functions);
450+
fixedpoint(it->first, it->second.body, goto_functions);
428451
}
429452

430453
void static_analysis_baset::concurrent_fixedpoint(
@@ -442,16 +465,32 @@ void static_analysis_baset::concurrent_fixedpoint(
442465
generate_state(sh_target);
443466
statet &shared_state=get_state(sh_target);
444467

445-
typedef std::list<std::pair<goto_programt const*,
446-
goto_programt::const_targett> > thread_wlt;
468+
struct wl_entryt
469+
{
470+
wl_entryt(
471+
const irep_idt &_function_identifier,
472+
const goto_programt &_goto_program,
473+
locationt _location)
474+
: function_identifier(_function_identifier),
475+
goto_program(&_goto_program),
476+
location(_location)
477+
{
478+
}
479+
480+
irep_idt function_identifier;
481+
const goto_programt *goto_program;
482+
locationt location;
483+
};
484+
485+
typedef std::list<wl_entryt> thread_wlt;
447486
thread_wlt thread_wl;
448487

449488
forall_goto_functions(it, goto_functions)
450489
forall_goto_program_instructions(t_it, it->second.body)
451490
{
452491
if(is_threaded(t_it))
453492
{
454-
thread_wl.push_back(std::make_pair(&(it->second.body), t_it));
493+
thread_wl.push_back(wl_entryt(it->first, it->second.body, t_it));
455494

456495
goto_programt::const_targett l_end=
457496
it->second.body.instructions.end();
@@ -472,16 +511,21 @@ void static_analysis_baset::concurrent_fixedpoint(
472511
for(const auto &thread : thread_wl)
473512
{
474513
working_sett working_set;
475-
put_in_working_set(working_set, thread.second);
514+
put_in_working_set(working_set, thread.location);
476515

477-
statet &begin_state=get_state(thread.second);
478-
merge(begin_state, shared_state, thread.second);
516+
statet &begin_state = get_state(thread.location);
517+
merge(begin_state, shared_state, thread.location);
479518

480519
while(!working_set.empty())
481520
{
482521
goto_programt::const_targett l=get_next(working_set);
483522

484-
visit(l, working_set, *thread.first, goto_functions);
523+
visit(
524+
thread.function_identifier,
525+
l,
526+
working_set,
527+
*thread.goto_program,
528+
goto_functions);
485529

486530
// the underlying domain must make sure that the final state
487531
// carries all possible values; otherwise we would need to

src/analyses/static_analysis.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,10 @@ class domain_baset
5858

5959
virtual void transform(
6060
const namespacet &ns,
61+
const irep_idt &function_from,
6162
locationt from,
62-
locationt to)=0;
63+
const irep_idt &function_to,
64+
locationt to) = 0;
6365

6466
virtual void output(
6567
const namespacet &,
@@ -130,6 +132,7 @@ class static_analysis_baset
130132
virtual void update(const goto_functionst &goto_functions);
131133

132134
virtual void operator()(
135+
const irep_idt &function_identifier,
133136
const goto_programt &goto_program);
134137

135138
virtual void operator()(
@@ -193,6 +196,7 @@ class static_analysis_baset
193196

194197
// true = found something new
195198
bool fixedpoint(
199+
const irep_idt &function_identifier,
196200
const goto_programt &goto_program,
197201
const goto_functionst &goto_functions);
198202

@@ -206,6 +210,7 @@ class static_analysis_baset
206210

207211
// true = found something new
208212
bool visit(
213+
const irep_idt &function_identifier,
209214
locationt l,
210215
working_sett &working_set,
211216
const goto_programt &goto_program,
@@ -237,14 +242,18 @@ class static_analysis_baset
237242

238243
// function calls
239244
void do_function_call_rec(
240-
locationt l_call, locationt l_return,
245+
const irep_idt &calling_function,
246+
locationt l_call,
247+
locationt l_return,
241248
const exprt &function,
242249
const exprt::operandst &arguments,
243250
statet &new_state,
244251
const goto_functionst &goto_functions);
245252

246253
void do_function_call(
247-
locationt l_call, locationt l_return,
254+
const irep_idt &calling_function,
255+
locationt l_call,
256+
locationt l_return,
248257
const goto_functionst &goto_functions,
249258
const goto_functionst::function_mapt::const_iterator f_it,
250259
const exprt::operandst &arguments,

src/pointer-analysis/value_set_domain.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ class value_set_domain_templatet:public domain_baset
4747

4848
virtual void transform(
4949
const namespacet &ns,
50+
const irep_idt &function_from,
5051
locationt from_l,
52+
const irep_idt &function_to,
5153
locationt to_l);
5254

5355
virtual void get_reference_set(

src/pointer-analysis/value_set_domain_transform.inc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ Author: Daniel Kroening, kroening@kroening.com
1616
template<class VST>
1717
void value_set_domain_templatet<VST>::transform(
1818
const namespacet &ns,
19+
const irep_idt &function_from,
1920
locationt from_l,
21+
const irep_idt &function_to,
2022
locationt to_l)
2123
{
2224
switch(from_l->type)
@@ -51,7 +53,7 @@ void value_set_domain_templatet<VST>::transform(
5153
to_code_function_call(from_l->code);
5254

5355
value_set.do_function_call(
54-
to_l->function, code.arguments(), ns);
56+
function_to, code.arguments(), ns);
5557
}
5658
break;
5759

0 commit comments

Comments
 (0)