@@ -52,24 +52,32 @@ void label_function_pointer_call_sites(goto_modelt &goto_model)
52
52
goto_model.symbol_table .lookup_ref (call_site_symbol_name)
53
53
.symbol_expr ();
54
54
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
57
63
auto assign_instruction = goto_programt::make_assignment (
58
64
code_assignt{new_function_pointer,
59
65
function_pointer_dereference.pointer ()},
60
66
source_location);
61
67
62
68
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
73
81
});
74
82
}
75
83
}
0 commit comments