@@ -52,24 +52,32 @@ void label_function_pointer_call_sites(goto_modelt &goto_model)
5252 goto_model.symbol_table .lookup_ref (call_site_symbol_name)
5353 .symbol_expr ();
5454
55- // add assignment to the new function pointer variable, followed by a
56- // call of the new variable
55+ // add a DECL instruction for the function pointer variable
56+ auto decl_instruction =
57+ goto_programt::make_decl (new_function_pointer, source_location);
58+
59+ goto_function.second .body .insert_before_swap (it, decl_instruction);
60+ ++it;
61+
62+ // add assignment to the new variable
5763 auto assign_instruction = goto_programt::make_assignment (
5864 code_assignt{new_function_pointer,
5965 function_pointer_dereference.pointer ()},
6066 source_location);
6167
6268 goto_function.second .body .insert_before_swap (it, assign_instruction);
63- const auto next = std::next (it);
64- to_code_function_call (next->code_nonconst ()).function () =
65- dereference_exprt{new_function_pointer};
66- // we need to increment the iterator once more (in addition to the
67- // increment already done by for_each_goto_function_if()). This is
68- // because insert_before_swap() inserts a new instruction after the
69- // instruction pointed to by it (and then swaps the contents with the
70- // previous instruction). We need to increment the iterator as we also
71- // need to skip over this newly inserted instruction.
72- it++;
69+ ++it;
70+
71+ // transform original call into a call to the new variable
72+ it->call_function () = dereference_exprt{new_function_pointer};
73+ ++it;
74+
75+ // add a DEAD instruction for the new variable
76+ auto dead_instruction =
77+ goto_programt::make_dead (new_function_pointer, source_location);
78+ goto_function.second .body .insert_before_swap (it, dead_instruction);
79+ // the iterator now points to the DEAD instruction and will be
80+ // incremented by the outer loop
7381 });
7482 }
7583}
0 commit comments