@@ -96,6 +96,28 @@ void remove_virtual_functionst::remove_virtual_function(
96
96
virtual_dispatch_fallback_actiont::CALL_LAST_FUNCTION);
97
97
}
98
98
99
+ // / Create a concrete function call to replace a virtual one
100
+ // / \param call [in/out]: the function call to update
101
+ // / \param function_symbol: the function to be called
102
+ // / \param ns: namespace
103
+ static void create_static_function_call (
104
+ code_function_callt &call,
105
+ const symbol_exprt &function_symbol,
106
+ const namespacet &ns)
107
+ {
108
+ call.function () = function_symbol;
109
+ // Cast the `this` pointer to the correct type for the new callee:
110
+ const auto &callee_type =
111
+ to_code_type (ns.lookup (function_symbol.get_identifier ()).type );
112
+ const code_typet::parametert *this_param = callee_type.get_this ();
113
+ INVARIANT (
114
+ this_param != nullptr ,
115
+ " Virtual function callees must have a `this` argument" );
116
+ typet need_type = this_param->type ();
117
+ if (!type_eq (call.arguments ()[0 ].type (), need_type, ns))
118
+ call.arguments ()[0 ].make_typecast (need_type);
119
+ }
120
+
99
121
void remove_virtual_functionst::remove_virtual_function (
100
122
goto_programt &goto_program,
101
123
goto_programt::targett target,
@@ -121,8 +143,10 @@ void remove_virtual_functionst::remove_virtual_function(
121
143
if (functions.begin ()->symbol_expr ==symbol_exprt ())
122
144
target->make_skip ();
123
145
else
124
- to_code_function_call (target->code ).function ()=
125
- functions.begin ()->symbol_expr ;
146
+ {
147
+ create_static_function_call (
148
+ to_code_function_call (target->code ), functions.front ().symbol_expr , ns);
149
+ }
126
150
return ;
127
151
}
128
152
@@ -187,18 +211,8 @@ void remove_virtual_functionst::remove_virtual_function(
187
211
{
188
212
// call function
189
213
t1->make_function_call (code);
190
- auto &newcall=to_code_function_call (t1->code );
191
- newcall.function ()=fun.symbol_expr ;
192
- // Cast the `this` pointer to the correct type for the new callee:
193
- const auto &callee_type=
194
- to_code_type (ns.lookup (fun.symbol_expr .get_identifier ()).type );
195
- const code_typet::parametert *this_param = callee_type.get_this ();
196
- INVARIANT (
197
- this_param != nullptr ,
198
- " Virtual function callees must have a `this` argument" );
199
- typet need_type=this_param->type ();
200
- if (!type_eq (newcall.arguments ()[0 ].type (), need_type, ns))
201
- newcall.arguments ()[0 ].make_typecast (need_type);
214
+ create_static_function_call (
215
+ to_code_function_call (t1->code ), fun.symbol_expr , ns);
202
216
}
203
217
else
204
218
{
0 commit comments