Skip to content

Commit 35e2b3d

Browse files
authored
Merge pull request #3843 from tautschnig/function-goto_rw
goto_rw: store function name alongside instruction reference [blocks: #3126]
2 parents 9fe58f6 + 2cf0109 commit 35e2b3d

File tree

5 files changed

+102
-53
lines changed

5 files changed

+102
-53
lines changed

src/analyses/dependence_graph.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ void dep_graph_domaint::data_dependencies(
162162
value_setst &value_sets=
163163
dep_graph.reaching_definitions().get_value_sets();
164164
rw_range_set_value_sett rw_set(ns, value_sets);
165-
goto_rw(to, rw_set);
165+
goto_rw(to->function, to, rw_set);
166166

167167
forall_rw_range_set_r_objects(it, rw_set)
168168
{

src/analyses/goto_rw.cpp

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -717,35 +717,40 @@ void rw_guarded_range_set_value_sett::add(
717717
{range_start, {range_end, guard.as_expr()}});
718718
}
719719

720-
void goto_rw(goto_programt::const_targett target,
721-
const code_assignt &assign,
722-
rw_range_sett &rw_set)
720+
static void goto_rw(
721+
const irep_idt &function,
722+
goto_programt::const_targett target,
723+
const code_assignt &assign,
724+
rw_range_sett &rw_set)
723725
{
724-
rw_set.get_objects_rec(target, rw_range_sett::get_modet::LHS_W, assign.lhs());
725-
rw_set.get_objects_rec(target, rw_range_sett::get_modet::READ, assign.rhs());
726+
rw_set.get_objects_rec(
727+
function, target, rw_range_sett::get_modet::LHS_W, assign.lhs());
728+
rw_set.get_objects_rec(
729+
function, target, rw_range_sett::get_modet::READ, assign.rhs());
726730
}
727731

728-
void goto_rw(goto_programt::const_targett target,
729-
const code_function_callt &function_call,
730-
rw_range_sett &rw_set)
732+
static void goto_rw(
733+
const irep_idt &function,
734+
goto_programt::const_targett target,
735+
const code_function_callt &function_call,
736+
rw_range_sett &rw_set)
731737
{
732738
if(function_call.lhs().is_not_nil())
733739
rw_set.get_objects_rec(
734-
target,
735-
rw_range_sett::get_modet::LHS_W,
736-
function_call.lhs());
740+
function, target, rw_range_sett::get_modet::LHS_W, function_call.lhs());
737741

738742
rw_set.get_objects_rec(
739-
target,
740-
rw_range_sett::get_modet::READ,
741-
function_call.function());
743+
function, target, rw_range_sett::get_modet::READ, function_call.function());
742744

743745
forall_expr(it, function_call.arguments())
744-
rw_set.get_objects_rec(target, rw_range_sett::get_modet::READ, *it);
746+
rw_set.get_objects_rec(
747+
function, target, rw_range_sett::get_modet::READ, *it);
745748
}
746749

747-
void goto_rw(goto_programt::const_targett target,
748-
rw_range_sett &rw_set)
750+
void goto_rw(
751+
const irep_idt &function,
752+
goto_programt::const_targett target,
753+
rw_range_sett &rw_set)
749754
{
750755
switch(target->type)
751756
{
@@ -758,9 +763,7 @@ void goto_rw(goto_programt::const_targett target,
758763
case ASSUME:
759764
case ASSERT:
760765
rw_set.get_objects_rec(
761-
target,
762-
rw_range_sett::get_modet::READ,
763-
target->guard);
766+
function, target, rw_range_sett::get_modet::READ, target->guard);
764767
break;
765768

766769
case RETURN:
@@ -769,6 +772,7 @@ void goto_rw(goto_programt::const_targett target,
769772
to_code_return(target->code);
770773
if(code_return.has_return_value())
771774
rw_set.get_objects_rec(
775+
function,
772776
target,
773777
rw_range_sett::get_modet::READ,
774778
code_return.return_value());
@@ -780,7 +784,8 @@ void goto_rw(goto_programt::const_targett target,
780784
if(target->code.get(ID_statement)==ID_printf)
781785
{
782786
forall_expr(it, target->code.operands())
783-
rw_set.get_objects_rec(target, rw_range_sett::get_modet::READ, *it);
787+
rw_set.get_objects_rec(
788+
function, target, rw_range_sett::get_modet::READ, *it);
784789
}
785790
break;
786791

@@ -797,35 +802,40 @@ void goto_rw(goto_programt::const_targett target,
797802
break;
798803

799804
case ASSIGN:
800-
goto_rw(target, to_code_assign(target->code), rw_set);
805+
goto_rw(function, target, to_code_assign(target->code), rw_set);
801806
break;
802807

803808
case DEAD:
804809
rw_set.get_objects_rec(
810+
function,
805811
target,
806812
rw_range_sett::get_modet::LHS_W,
807813
to_code_dead(target->code).symbol());
808814
break;
809815

810816
case DECL:
811817
rw_set.get_objects_rec(
812-
to_code_decl(target->code).symbol().type());
818+
function, target, to_code_decl(target->code).symbol().type());
813819
rw_set.get_objects_rec(
820+
function,
814821
target,
815822
rw_range_sett::get_modet::LHS_W,
816823
to_code_decl(target->code).symbol());
817824
break;
818825

819826
case FUNCTION_CALL:
820-
goto_rw(target, to_code_function_call(target->code), rw_set);
827+
goto_rw(function, target, to_code_function_call(target->code), rw_set);
821828
break;
822829
}
823830
}
824831

825-
void goto_rw(const goto_programt &goto_program, rw_range_sett &rw_set)
832+
void goto_rw(
833+
const irep_idt &function,
834+
const goto_programt &goto_program,
835+
rw_range_sett &rw_set)
826836
{
827837
forall_goto_program_instructions(i_it, goto_program)
828-
goto_rw(i_it, rw_set);
838+
goto_rw(function, i_it, rw_set);
829839
}
830840

831841
void goto_rw(const goto_functionst &goto_functions,
@@ -839,6 +849,6 @@ void goto_rw(const goto_functionst &goto_functions,
839849
{
840850
const goto_programt &body=f_it->second.body;
841851

842-
goto_rw(body, rw_set);
852+
goto_rw(f_it->first, body, rw_set);
843853
}
844854
}

src/analyses/goto_rw.h

Lines changed: 54 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,15 @@ Date: April 2010
3232
class rw_range_sett;
3333
class goto_modelt;
3434

35-
void goto_rw(goto_programt::const_targett target,
36-
rw_range_sett &rw_set);
35+
void goto_rw(
36+
const irep_idt &function,
37+
goto_programt::const_targett target,
38+
rw_range_sett &rw_set);
3739

38-
void goto_rw(const goto_programt &,
39-
rw_range_sett &rw_set);
40+
void goto_rw(
41+
const irep_idt &function,
42+
const goto_programt &,
43+
rw_range_sett &rw_set);
4044

4145
void goto_rw(const goto_functionst &,
4246
const irep_idt &function,
@@ -141,14 +145,21 @@ class rw_range_sett
141145
enum class get_modet { LHS_W, READ };
142146

143147
virtual void get_objects_rec(
148+
const irep_idt &,
144149
goto_programt::const_targett,
145150
get_modet mode,
146151
const exprt &expr)
147152
{
148153
get_objects_rec(mode, expr);
149154
}
150155

151-
virtual void get_objects_rec(const typet &type);
156+
virtual void get_objects_rec(
157+
const irep_idt &,
158+
goto_programt::const_targett,
159+
const typet &type)
160+
{
161+
get_objects_rec(type);
162+
}
152163

153164
void output(std::ostream &out) const;
154165

@@ -161,6 +172,8 @@ class rw_range_sett
161172
get_modet mode,
162173
const exprt &expr);
163174

175+
virtual void get_objects_rec(const typet &type);
176+
164177
virtual void get_objects_complex_real(
165178
get_modet mode,
166179
const complex_real_exprt &expr,
@@ -265,28 +278,41 @@ class rw_range_set_value_sett:public rw_range_sett
265278
{
266279
}
267280

268-
using rw_range_sett::get_objects_rec;
269-
270-
virtual void get_objects_rec(
281+
void get_objects_rec(
282+
const irep_idt &_function,
271283
goto_programt::const_targett _target,
272284
get_modet mode,
273-
const exprt &expr)
285+
const exprt &expr) override
274286
{
287+
function = _function;
275288
target=_target;
276289

277290
rw_range_sett::get_objects_rec(mode, expr);
278291
}
279292

293+
void get_objects_rec(
294+
const irep_idt &_function,
295+
goto_programt::const_targett _target,
296+
const typet &type) override
297+
{
298+
function = _function;
299+
target = _target;
300+
301+
rw_range_sett::get_objects_rec(type);
302+
}
303+
280304
protected:
281305
value_setst &value_sets;
282-
306+
irep_idt function;
283307
goto_programt::const_targett target;
284308

285-
virtual void get_objects_dereference(
309+
using rw_range_sett::get_objects_rec;
310+
311+
void get_objects_dereference(
286312
get_modet mode,
287313
const dereference_exprt &deref,
288314
const range_spect &range_start,
289-
const range_spect &size);
315+
const range_spect &size) override;
290316
};
291317

292318
class guarded_range_domaint:public range_domain_baset
@@ -338,32 +364,41 @@ class rw_guarded_range_set_value_sett:public rw_range_set_value_sett
338364
return static_cast<const guarded_range_domaint &>(*it->second);
339365
}
340366

341-
virtual void get_objects_rec(
367+
void get_objects_rec(
368+
const irep_idt &_function,
342369
goto_programt::const_targett _target,
343370
get_modet mode,
344-
const exprt &expr)
371+
const exprt &expr) override
345372
{
346373
guard = true_exprt();
347374

348-
rw_range_set_value_sett::get_objects_rec(_target, mode, expr);
375+
rw_range_set_value_sett::get_objects_rec(_function, _target, mode, expr);
376+
}
377+
378+
void get_objects_rec(
379+
const irep_idt &function,
380+
goto_programt::const_targett target,
381+
const typet &type) override
382+
{
383+
rw_range_sett::get_objects_rec(function, target, type);
349384
}
350385

351386
protected:
352387
guardt guard;
353388

354389
using rw_range_sett::get_objects_rec;
355390

356-
virtual void get_objects_if(
391+
void get_objects_if(
357392
get_modet mode,
358393
const if_exprt &if_expr,
359394
const range_spect &range_start,
360-
const range_spect &size);
395+
const range_spect &size) override;
361396

362-
virtual void add(
397+
void add(
363398
get_modet mode,
364399
const irep_idt &identifier,
365400
const range_spect &range_start,
366-
const range_spect &range_end);
401+
const range_spect &range_end) override;
367402
};
368403

369404
#endif // CPROVER_ANALYSES_GOTO_RW_H

src/analyses/reaching_definitions.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,13 @@ void rd_range_domaint::transform(
9191
transform_function_call(ns, function_from, from, function_to, *rd);
9292
// cleanup parameters
9393
else if(from->is_end_function())
94-
transform_end_function(ns, function_from, from, to, *rd);
94+
transform_end_function(ns, function_from, from, function_to, to, *rd);
9595
// lhs assignments
9696
else if(from->is_assign())
97-
transform_assign(ns, from, from, *rd);
97+
transform_assign(ns, from, function_from, from, *rd);
9898
// initial (non-deterministic) value
9999
else if(from->is_decl())
100-
transform_assign(ns, from, from, *rd);
100+
transform_assign(ns, from, function_from, from, *rd);
101101

102102
#if 0
103103
// handle return values
@@ -233,14 +233,15 @@ void rd_range_domaint::transform_function_call(
233233
{
234234
// handle return values of undefined functions
235235
if(to_code_function_call(from->code).lhs().is_not_nil())
236-
transform_assign(ns, from, from, rd);
236+
transform_assign(ns, from, function_from, from, rd);
237237
}
238238
}
239239

240240
void rd_range_domaint::transform_end_function(
241241
const namespacet &ns,
242242
const irep_idt &function_from,
243243
locationt from,
244+
const irep_idt &function_to,
244245
locationt to,
245246
reaching_definitions_analysist &rd)
246247
{
@@ -301,18 +302,19 @@ void rd_range_domaint::transform_end_function(
301302
assert(rd_state!=0);
302303
rd_state->
303304
#endif
304-
transform_assign(ns, from, call, rd);
305+
transform_assign(ns, from, function_to, call, rd);
305306
}
306307
}
307308

308309
void rd_range_domaint::transform_assign(
309310
const namespacet &ns,
310311
locationt from,
312+
const irep_idt &function_to,
311313
locationt to,
312314
reaching_definitions_analysist &rd)
313315
{
314316
rw_range_set_value_sett rw_set(ns, rd.get_value_sets());
315-
goto_rw(to, rw_set);
317+
goto_rw(function_to, to, rw_set);
316318
const bool is_must_alias=rw_set.get_w_set().size()==1;
317319

318320
forall_rw_range_set_w_objects(it, rw_set)

src/analyses/reaching_definitions.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,11 +309,13 @@ class rd_range_domaint:public ai_domain_baset
309309
const namespacet &ns,
310310
const irep_idt &function_from,
311311
locationt from,
312+
const irep_idt &function_to,
312313
locationt to,
313314
reaching_definitions_analysist &rd);
314315
void transform_assign(
315316
const namespacet &ns,
316317
locationt from,
318+
const irep_idt &function_to,
317319
locationt to,
318320
reaching_definitions_analysist &rd);
319321

0 commit comments

Comments
 (0)