File tree Expand file tree Collapse file tree 8 files changed +53
-19
lines changed Expand file tree Collapse file tree 8 files changed +53
-19
lines changed Original file line number Diff line number Diff line change @@ -76,7 +76,7 @@ void dep_graph_domaint::control_dependencies(
7676 from->is_assume ())
7777 control_deps.insert (from);
7878
79- const irep_idt id=goto_programt::get_function_id ( from) ;
79+ const irep_idt id=from-> function ;
8080 const cfg_post_dominatorst &pd=dep_graph.cfg_post_dominators ().at (id);
8181
8282 // check all candidates for M
Original file line number Diff line number Diff line change @@ -150,7 +150,7 @@ void full_slicert::add_jumps(
150150 continue ;
151151 }
152152
153- const irep_idt id=goto_programt::get_function_id ( j.PC ) ;
153+ const irep_idt id=j.PC -> function ;
154154 const cfg_post_dominatorst &pd=post_dominators.at (id);
155155
156156 cfg_post_dominatorst::cfgt::entry_mapt::const_iterator e=
@@ -184,7 +184,7 @@ void full_slicert::add_jumps(
184184
185185 if (cfg[entry->second ].node_required )
186186 {
187- const irep_idt id2=goto_programt::get_function_id (*d_it);
187+ const irep_idt id2=(*d_it)-> function ;
188188 INVARIANT (id==id2,
189189 " goto/jump expected to be within a single function" );
190190
Original file line number Diff line number Diff line change @@ -213,9 +213,8 @@ void goto_convert_functionst::convert_function(
213213 // add "end of function"
214214 f.body .destructive_append (tmp_end_function);
215215
216- // do function tags
217- Forall_goto_program_instructions (i_it, f.body )
218- i_it->function =identifier;
216+ // do function tags (they are empty at this point)
217+ f.update_instructions_function (identifier);
219218
220219 f.body .update ();
221220
Original file line number Diff line number Diff line change @@ -62,6 +62,14 @@ class goto_function_templatet
6262 parameter_identifiers.clear ();
6363 }
6464
65+ // / update the function member in each instruction
66+ // / \param function_id: the `function_id` used for assigning empty function
67+ // / members
68+ void update_instructions_function (const irep_idt &function_id)
69+ {
70+ body.update_instructions_function (function_id);
71+ }
72+
6573 void swap (goto_function_templatet &other)
6674 {
6775 body.swap (other.body );
@@ -149,12 +157,23 @@ class goto_functions_templatet
149157 void compute_target_numbers ();
150158 void compute_incoming_edges ();
151159
160+ // / update the function member in each instruction by setting it to
161+ // / the goto function's identifier
162+ void update_instructions_function ()
163+ {
164+ for (auto &func : function_map)
165+ {
166+ func.second .update_instructions_function (func.first );
167+ }
168+ }
169+
152170 void update ()
153171 {
154172 compute_incoming_edges ();
155173 compute_target_numbers ();
156174 compute_location_numbers ();
157175 compute_loop_numbers ();
176+ update_instructions_function ();
158177 }
159178
160179 static inline irep_idt entry_point ()
Original file line number Diff line number Diff line change @@ -103,6 +103,13 @@ class goto_model_functiont
103103 goto_functions.compute_location_numbers (goto_function.body );
104104 }
105105
106+ // / Updates the empty function member of each instruction by setting them
107+ // / to `function_id`
108+ void update_instructions_function ()
109+ {
110+ goto_function.update_instructions_function (function_id);
111+ }
112+
106113 // / Get symbol table
107114 // / \return journalling symbol table that (a) wraps the global symbol table,
108115 // / and (b) has recorded all symbol mutations (insertions, updates and
Original file line number Diff line number Diff line change @@ -386,21 +386,12 @@ class goto_program_templatet
386386 return t;
387387 }
388388
389- static const irep_idt get_function_id (
390- const_targett l)
391- {
392- while (!l->is_end_function ())
393- ++l;
394-
395- return l->function ;
396- }
397-
398389 static const irep_idt get_function_id (
399390 const goto_program_templatet<codeT, guardT> &p)
400391 {
401- assert (!p.empty ());
392+ PRECONDITION (!p.empty ());
402393
403- return get_function_id (-- p.instructions .end ()) ;
394+ return p.instructions .back (). function ;
404395 }
405396
406397 template <typename Target>
@@ -521,6 +512,22 @@ class goto_program_templatet
521512 }
522513 }
523514
515+ // / Sets the `function` member of each instruction if not yet set
516+ // / Note that a goto program need not be a goto function and therefore,
517+ // / we cannot do this in update(), but only at the level of
518+ // / of goto_functionst where goto programs are guaranteed to be
519+ // / named functions.
520+ void update_instructions_function (const irep_idt &function_id)
521+ {
522+ for (auto &instruction : instructions)
523+ {
524+ if (instruction.function .empty ())
525+ {
526+ instruction.function = function_id;
527+ }
528+ }
529+ }
530+
524531 // / Compute location numbers
525532 void compute_location_numbers ()
526533 {
Original file line number Diff line number Diff line change @@ -244,8 +244,7 @@ void remove_returnst::operator()(
244244 if (goto_function.body .empty ())
245245 return ;
246246
247- replace_returns (
248- goto_programt::get_function_id (goto_function.body ), goto_function);
247+ replace_returns (model_function.get_function_id (), goto_function);
249248 do_function_calls (function_is_stub, goto_function.body );
250249}
251250
Original file line number Diff line number Diff line change @@ -721,6 +721,9 @@ void jbmc_parse_optionst::process_goto_function(
721721 symbol_table.lookup_ref (new_symbol_name),
722722 symbol_table);
723723 }
724+
725+ // update the function member in each instruction
726+ function.update_instructions_function ();
724727 }
725728
726729 catch (const char *e)
You can’t perform that action at this time.
0 commit comments